26

I am using the request module in Node.js to do a put request. My code looks like this

var request = require('request');
var data = {foo: "bar", woo: "car"};

request({
   method: 'PUT',
   uri: myURL,
   multipart: [{
       'content-type':'application/json',
       body: JSON.stringify(data) 
   }]
}, function(error, request, body){
   console.log(body);
});

When I run this I get an error:

"Unsupported content with type: application/json"

1 Answer 1

39

Just try it like this:

request({ url: url, method: 'PUT', json: {foo: "bar", woo: "car"}}, callback)

Sign up to request clarification or add additional context in comments.

3 Comments

And where would I include headers?
headers is just a nested JSON in the options JSON.
what about a put request with a file upload?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.