【发布时间】:2015-03-07 17:55:20
【问题描述】:
我在向我的节点服务器发送 json 数据时遇到问题
我试过了
var req = {
method: 'POST',
url: 'http://33.33.33.15/user/signin',
headers : {
'Content-Type' : 'application/x-www-form-urlencoded'
},
data: {test:"test"}
};
当我console.log()req.body 有
{ '{"test":"test"}': '' }
当我尝试使用时
var req = {
method: 'POST',
url: 'http://33.33.33.15/user/signin',
headers : {
'Content-Type' : 'application/x-www-form-urlencoded'
},
data: 'test=test'
};
我在服务器上成绩不错
我将内容类型设置为 application/x-www-form-urlencoded 以允许跨域
在我拥有的服务器上
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
感谢您的帮助
【问题讨论】: