在我将 app.use(express.bodyParser()) 添加到我的代码中之前,一切正常。
添加后,快递一直向我抛出无效的 json 错误。我想念什么?这是我使用的命令行。
curl -d '{"disc":"1"}' -H "Content-Type: application/json" http://localhost:8080
这是日志
Error: invalid json
at Object.exports.error (C:\Users\123\Documents\googledrive\Google Drive\nodejs\node_modules\express\node_modules\connect\lib\utils.js:60:13)
at IncomingMessage.module.exports (C:\Users\123\Documents\googledrive\Googl
Drive\nodejs\node_modules\express\node_modules\connect\lib\middleware\j
on.js:74:71)
at IncomingMessage.EventEmitter.emit (events.js:93:17)
at IncomingMessage._emitEnd (http.js:366:10)
at HTTPParser.parserOnMessageComplete [as onMessageComplete] (http.js:149:2
)
at Socket.socket.ondata (http.js:1825:22)
at TCP.onread (net.js:404:27)
这是我使用的代码
var express = require("express");
var app = express();
app.use(express.bodyParser());
app.post("/",function(request,response){
response.send("hello");
response.end();
});
var port = 8080;
app.listen(port);
console.log("listen on "+port);