Tag: 有效负载

从Node.js服务器本地访问JSON POST有效内容

考虑下面的一个Node.js服务器的HTTP POST调用: curl -H "Content-Type: application/json" \ -X POST \ -d '{"jsonKey":"jsonValue"}' \ 'http://localhost:8080?abcd=efgh' 我想访问POST请求的URL参数和JSON负载。 通过导入url.parse访问URL参数非常简单: var server = http.createServer(function(req, res) { // Parse the params – prints "{ abcd: 'efgh' }" var URLParams = url.parse(req.url, true).query; console.log(URLParams); // How do I access the JSON payload as an object? } 但是,如何使用本地Node.js库(不包括任何npm导入)来访问JSON负载? 我试过了什么 打印req到console.log ,但没有findPOST对象 阅读req的文档,这是typeshttp.IncomingMessage