I tried to use this function to get req info in routes , I can get req.headers, but req.body is empty, I really want to know how to get my XML content, Is anybody could tell me how? Please馃檹
function:
onBeforeCall(ctx, route, req, res) {
console.log('*****', req.headers);
console.log('*****', req.body);
},
req.headers:
{ host: '....',
'user-agent': '....',
accept: "* / *",
'content-type': 'text/xml',
'content-length': '343',
'cache-control': 'no-cache' }
req.body:
{}
Wrong repo. It's relevant to moleculer-web instead of this.
By the way:
module.exports = {
name: "api",
mixins: [ApiService],
settings: {
routes: [{
path: "/api",
bodyParsers: {
json: false,
raw: {
// https://github.com/expressjs/body-parser#bodyparserrawoptions
type: "text/xml"
}
},
onBeforeCall(ctx, route, req, res) {
console.log("Headers", req.headers);
console.log("Raw body", req.body);
},
}]
},
}
Headers { 'content-type': 'text/xml',
'user-agent': 'PostmanRuntime/7.13.0',
accept: '*/*',
'postman-token': '1bf11618-a290-4f15-ace8-67da3ccf6096',
host: 'localhost:3000',
'accept-encoding': 'gzip, deflate',
'content-length': '172',
connection: 'keep-alive' }
Raw body <Buffer 0d 0a 3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e 3d 22 31 2e 30 22 20 65 6e 63 6f 64 69 6e 67 3d 22 55 54 46 2d 38 22 3f 3e 0d 0a 3c 6e 6f 74 65 3e 0d 0a ... >
Thanks a lot, It works for me.
Most helpful comment
Wrong repo. It's relevant to moleculer-web instead of this.
By the way: