为什么 Hapi.js POST 处理程序返回空负载?

Why is Hapi.js POST handler returning an empty payload?

我有一个接受 POST 调用的 Hapi 路由,但是 request returns 一个 null 负载值。

server.route({
    method: ['POST', 'PUT'],
    path: '/create_note',
    handler: function (request, reply) {
        console.log(request.payload); // returns `null`
        return reply(request.payload);
    }
});

我正在使用 Postman 向 http://localhost:8000/create_note?name=test 发送 POST 呼叫。

在处理函数中,console.log(request.payload) returns null.

我是不是做错了什么?

您正在使用 ?name=test 传递查询字符串参数,而不是 POST 请求负载。

您可以通过引用request.query访问查询参数。

http://localhost:8000/create_note?name=test 的 HTTP 请求将产生:

console.log(request.query); // {name: 'test'}