Wednesday, 17 May 2017

convert curl -F request to nodejs request

I have this line with curl and it's working fine:

curl -X POST -F document=@name_of_document_with_json_inside.txt http://some_url/json/name?signature=bd87b1e4b679092a6946de0c6f623567

I want to change this and POST my json document with nodejs

My current code is:

var request = require('request');

var clientServerOptions = {
  uri: 'http://some_url/json/name?signature=bd87b1e4b679092a6946de0c6f623567',
  body: JSON.stringify(postData),
  json: true,
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  }
}

request(clientServerOptions, function (error, response) {
  console.log(error,response.body);
  return;
});

From curl help i got that -F is for forms and in my curl i have a command that is posting field document:

-F/--form <name=content> Specify HTTP multipart POST data (H)

Can anyone help me out how to specify document field and post my json data in it?



via Nikola Stojanoski

No comments:

Post a Comment