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"
The request module is used to make HTTP calls. It is the simplest way of making HTTP calls in node. js using this request module. It follows redirects by default. Note: As of Feb 11th, 2020, request is fully deprecated.
Example code: var request = require('request') var options = { method: 'post', body: postData, // Javascript object json: true, // Use,If you are sending JSON data url: url, headers: { // Specify headers, If any } } request(options, function (err, res, body) { if (err) { console. log('Error :', err) return } console.
Request isn't really deprecated. It's no longer considering new features or breaking changes, but it is still being maintained. It's safe to use for the foreseeable future, but how good an idea it is to use it is up to the developer.
Just try it like this:
request({ url: url, method: 'PUT', json: {foo: "bar", woo: "car"}}, callback)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With