0

I have an URL to which i need to make an POST Call, given that i have Header Value, Request Body in JSON and the URl to make an POST Call.

Header      : {
                Authorization: "some_authorization_key",
                Content-Type: "application/json"
              }
URL         : http://someurl.com/somepath
input JSON  : {
                key : sdasddasdas,
                name: name
              }
request Method : POST

I need to POST call in node js using the above details.

Can anyone provide me the code how to make an POST call using the above details

Shayan Ghosh
  • 862
  • 6
  • 14
  • 1
    Possible duplicate of [How to make an HTTP POST request in node.js?](http://stackoverflow.com/questions/6158933/how-to-make-an-http-post-request-in-node-js) – XCS Apr 12 '16 at 10:08

1 Answers1

0

You may code like this using require library.

var request = require('request');  
    request.post(
        'http://www.nameofsite.com/yourpage',
        { form: { key: 'value' } },
        function (error, response, body) {
            if (!error && response.statusCode == 200) {
                console.log(body)
            }
        }
    );
Shayan Ghosh
  • 862
  • 6
  • 14
  • but i need to POST it with using the HEADER keys and the input JSON value. how can i post using header and input JSON value – Anand Vetrivel Apr 12 '16 at 10:27
  • 1
    request({ url: url, method: "POST", json: true, headers: { "content-type": "application/json", }, body: JSON.stringify(requestData) }, ... – Shayan Ghosh Apr 12 '16 at 10:48