Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么Hapi.js POST处理程序返回空负载?_Javascript_Hapijs - Fatal编程技术网

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

Javascript 为什么Hapi.js POST处理程序返回空负载?,javascript,hapijs,Javascript,Hapijs,我有一个接受POST呼叫的Hapi路由,但是请求返回有效负载的null值 server.route({ method: ['POST', 'PUT'], path: '/create_note', handler: function (request, reply) { console.log(request.payload); // returns `null` return reply(request.payload); } }

我有一个接受POST呼叫的Hapi路由,但是
请求
返回有效负载的
null

server.route({
    method: ['POST', 'PUT'],
    path: '/create_note',
    handler: function (request, reply) {
        console.log(request.payload); // returns `null`
        return reply(request.payload);
    }
});
我在用邮递员给
http://localhost:8000/create_note?name=test

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


我做错什么了吗?

您传递的是带有
?name=test的查询字符串参数,而不是POST请求负载

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

http://localhost:8000/create_note?name=test
将产生:

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

payload
是请求正文,除非您通过邮递员发送请求正文,
null
是预期值。