'form-data post request using https in node.js
How can I send form-data post request using http package?
I have working code with "request" package:
let result = await request({
url: getTokenURL,
method: "POST",
form: `login=${login}&password=${password}`
});
but I want do the same with native http
trying this:
let getToken = function(url, login, password){
return new Promise((resolve, reject) => {
let getTokenURL = `${url}`;
console.log(`requesting ${getTokenURL}`);
let httpRequest = http.request({
uri: getTokenURL,
port: 80,
method: 'POST',
form: `login=${login}&password=${password}`
}, (response) => {
let body = '';
response.on('data', (chunk) => {
body += chunk;
});
response.on('end', () => {
console.log(body);
return resolve(body);
});
});
});
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

