通过https JSON节点快递提交没有格式化
我有一个angularjs应用程序通过https发布到节点快递服务器。 angular度客户端使用标题发布:
headers: {'Content-Type': 'application/x-www-form-urlencoded'}})
在服务器上:
var bodyParser = require('body-parser'); app.use(bodyParser.urlencoded({ extended: false }));
这产生了一个如下的请求体:
{ '{"firstname":"hj","lastname":"hj"}': '' }
没有bodyParser,我根本没有任何身体。
显然我做错了什么。 有没有办法得到有效的json而不尝试解读上述请求体?
我相信你所缺less的是让bodyParser知道JSON
。
app.use(bodyParser.urlencoded({ extended: false })); // Place it below ^ your urlencoded line app.use(bodyParser.json()); // <-- this
MarkPieszak在他的文章和他的评论中是正确的:
headers: {'Content-Type': 'application/json'}})
我以某种方式不认为这将通过https工作