【发布时间】:2026-02-12 16:15:01
【问题描述】:
我正在寻找一种使用 Nodejs 在 RequestJS 中传递内容类型的方法。
现在我有这个作为参数:
'use strict';
request = require('request'),
app.register = function(req, res) {
request.post({
headers: {'Content-Type' : 'application/json'},
url: 'my.url.here',
form: req.body,
}).pipe(res);
}
但由于某种原因,服务器仍然说它是内容类型的 text/xml.. 谁能告诉我如何自定义这个?
【问题讨论】:
-
另外,如果您将 content-type 设置为 application/json,为什么要在表单选项中发送 req.body? json != 表单参数。 requirejs 是如何与此联系在一起的?
-
Req.body 是传入控制器的参数...