node.js - How do I add payload for requestjs REST call -
i've following code:
var request = require('request') ... var options = {     method: 'post',     rejectunauthorized: false,      url: '<my rest uri>',     headers: {     'content-type':json},     authorization:'basic',     auth: {        user: username,        password: password     }  }   ...
request(options, function (err, res, body) {       if (err) {         console.dir(err);         retmessage= err;         res.render(err);           return;       }       console.dir('headers', res.headers)       console.dir('status code', res.statuscode)       console.dir(body)     })   i'm trying invoke rest api needs json data payload. how add payload call?
put body property in options object. https://github.com/request/request#requestoptions-callback:
body - entity body patch, post , put requests. must buffer or string, unless json true. if json true, body must json-serializable object.
Comments
Post a Comment