javascript - Add parameters to HTTP POST request in Node.JS -


i've known way send simple http request using node.js following:

var http = require('http');  var options = {   host: 'example.com',   port: 80,   path: '/foo.html' };  http.get(options, function(resp){   resp.on('data', function(chunk){     //do chunk   }); }).on("error", function(e){   console.log("got error: " + e.message); }); 

i want know how embed parameters in body of post request , how capture them receiver module.

would mind using request library. sending post request becomes simple as

var options = { url: 'https://someurl.com', 'method': 'post',  'body': {"key":"val"}   };   request(options,function(error,response,body){    //do want callback functon }); 

the request library has shortcut post in request.post method in pass url make post request along data send url.

edit based on comment

to "capture" post request best if used kind of framework. since express popular 1 give example of express. in case not familiar express suggest reading getting started guide author himself.

all need create post route , callback function contain data posted url

app.post('/name-of-route',function(req,res){  console.log(req.body); //req.body contains post data posted url   }); 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -