Friday, 2 March 2018

Curl request with node

As far as I've searched, I can use request module to make a curl request.This tool converts a curl request to Nodejs request with request module.This is my original curl request:curl -i -X POST -F 'email=name@hotmail.com' -F 'password=123456' https://localhost/:3000/register When I do the conversion I get the following code:var request = require('request'); var options = { url: 'https://localhost/:3000/register', method: 'POST' }; function callback(error, response, body) { if (!error && response.statusCode == 200) { console.log(body); } } request(options, callback); Here my data is not included for some reason. So, I tried to add it as follows but when I run the code, I have no error but no response as wellvar request = require('request'); var options = { url: 'https://localhost/:3000/register', method: 'POST', form: { email: 'name@hotmail.com', password: '123456' } }; function callback(error, response, body) { if (!error && response.statusCode == 200) { console.log(body); } } request(options, callback);

Submitted March 03, 2018 at 02:25AM by eligloys

No comments:

Post a Comment