admin管理员组文章数量:1430034
I have a Hapi route that accepts a POST call, but the request
returns a null
value for the payload.
server.route({
method: ['POST', 'PUT'],
path: '/create_note',
handler: function (request, reply) {
console.log(request.payload); // returns `null`
return reply(request.payload);
}
});
I'm using Postman to send a POST call to http://localhost:8000/create_note?name=test
.
In the handler function, console.log(request.payload)
returns null
.
Am I doing something wrong?
I have a Hapi route that accepts a POST call, but the request
returns a null
value for the payload.
server.route({
method: ['POST', 'PUT'],
path: '/create_note',
handler: function (request, reply) {
console.log(request.payload); // returns `null`
return reply(request.payload);
}
});
I'm using Postman to send a POST call to http://localhost:8000/create_note?name=test
.
In the handler function, console.log(request.payload)
returns null
.
Am I doing something wrong?
Share Improve this question edited May 2, 2016 at 21:16 simon-p-r 3,7512 gold badges22 silver badges37 bronze badges asked May 2, 2016 at 14:18 parkerageeparkeragee 3231 gold badge3 silver badges14 bronze badges 1-
payload
is the request body, unless you're sending a request body through Postman,null
is the expected value. – Matt Harrison Commented May 2, 2016 at 16:38
1 Answer
Reset to default 7You are passing query string parameters with ?name=test
, not the POST request payload.
You can access the query parameters by referencing request.query
.
An HTTP request to http://localhost:8000/create_note?name=test
will yield:
console.log(request.query); // {name: 'test'}
本文标签: javascriptWhy is Hapijs POST handler returning an empty payloadStack Overflow
版权声明:本文标题:javascript - Why is Hapi.js POST handler returning an empty payload? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745552853a2663023.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论