RequestJS传递内容类型:application / json

时间:2015-07-08 16:11:46

标签: node.js requestjs

我正在尝试使用Nodejs在RequestJS中传递内容类型。

现在我把它作为params:

'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 .. 任何人都可以告诉我如何自定义它?

1 个答案:

答案 0 :(得分:0)

您应该使用json选项,而不是form,并且您不需要设置内容类型,json选项会为您执行此操作。

request.post({
  url: 'my.url.here',
  json: req.body
}).pipe(res);