Reputation: 1281
When using request, how do you set the request body? The form
parameter creates a body of key value pairs: foo=bar&baz=qux
, but how do you set the body to an arbitrary string?
Upvotes: 1
Views: 3124
Reputation: 1105
You can set request body in the options params.
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({test: 1});
};
request(options, function (err, res, body) {
// handle err or use response and response boy
});
Depending upon the content you want to send, you can provide the string needed.
Upvotes: 2