Posting data using net.request is not working. It's reaching the URL. But data not posted. My code is below. Please help me on this.
const net = remote.net;
const querystring = require('querystring');
//**
var postData = querystring.stringify({
'username' : 'test',
'password': 'test'
});
const request = net.request({
method: 'POST',
url: 'http://127.0.0.1/post.php',
});
request.on('error', (error) => {});
request.on('response', (response) => {});
request.write(postData);
request.end();
I know it's been a while. But for the next people who will have the same problem.
Don't forget you must be declare the size of your "postData" in the header. for example :
var postData = JSON.stringify({"q" : sqlQuery });
const request = net.request({
method: 'POST',
protocol: 'http:',
hostname: '127.0.0.1',
port: 3000,
path: '/select',
headers: {
'Content-Type': 'application/json',
'Content-Length': postData.length
}
})
request.on('response', (response) => {
.... // Something
})
request.write(postData)
request.end()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With