-1

I'm looking a way to pass a content-type in RequestJS using with Nodejs.

Right now I have this as 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);
}

But for some reason the server it still says it's a content-type text/xml.. Anyone can tell me how to customize this?

Ryan
  • 13
  • 1
  • 4
  • also, why are you sending req.body in the form option, if you're setting content-type to application/json? json != form params. How does requirejs tie into this? – Kevin B Jul 08 '15 at 16:20
  • Req.body is parameter that pass in the controler... – Ryan Jul 08 '15 at 16:30

1 Answers1

0

You should use the json option, not form, and you don't need to set the content type, the json option does that for you.

request.post({
  url: 'my.url.here',
  json: req.body
}).pipe(res);
Kevin B
  • 94,570
  • 16
  • 163
  • 180