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 postData = { id: "12345", title: "Some title", url: "some-url" };
var clientServerOptions = {
uri: 'http://some_url/json/name?signature=bd87b1e4b679092a6946de0c6f623567',
body: 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?
Update:
postData contains:
{ id: "12345", title: "Some title", url: "some-url" }
This is the data that is in name_of_document_with_json_inside.txt
I was told that i need to do it something like posting textarea with name=document:
<textarea name="document">JSON BLA BLA BLA</textarea>
So how to specify document= ?