To POST data with request module on Node.js, we call the request.post
method.
For instance, we write
const request = require("request");
request.post(
{
headers: { "content-type": "application/x-www-form-urlencoded" },
url: "http://localhost/test2.php",
body: "mes=heydude",
},
(error, response, body) => {
console.log(body);
}
);
to call request.post
with an object that has the headers
, url
and the request body
.
We get the response
and the response body
from the callback.