我通过body-parser进行post请求,index.js
如下:
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.use(express.json());
app.post('/', function(request, response){
console.log(request.body);
res.send("test");
});
app.get('/', function(req, res) {
res.send('Hello World!');
});
app.listen(8080, function() {
console.log('Example app listening on port 8080!');
});
重启docker没有问题,但运行命令是却出现问题:
curl -d {"user":"Someone"} -H "Content-Type: application/json" --url http://localhost:8080
报错:
Unexpected token u in JSON at position 1
at JSON.parse (<anonymous>)
请问怎么处理?