Go Down

Topic: node.js - HTTPS POST does not get response (Read 159 times) previous topic - next topic

rathodmanoj

Hi,
I have been using NODE for more than 2 years now. But suddenly, one of the code stopped working last week.

The code below raises a https POST request to a central server. It sends few request parameters using write method. But I am unable to get the response from central server.

I tried same code on RPi and working perfectly fine. But when I run it on Yun, it does not get response (I used to get it until last week).
Code: [Select]

var RETRY_INTERVAL = 10000;

 
var https = require('https');

https.globalAgent.options.rejectUnauthorized = false;
https.globalAgent.options.requestCert = false;
https.globalAgent.options.agent = false;


function test() {
var qrystr = require('querystring');
var qryData = {
    'name': 'pqr',
    'ln': 'mno'
};
var queryData = qrystr.stringify(qryData);
var options = {
  host: 'www.bigwigtech.com',
  port: '443',
  path: '/test/test.php',
  method: 'POST',
  headers: {
  'Content-Type': 'application/x-www-form-urlencoded',
  'Content-Length': Buffer.byteLength(queryData)
  }
};
console.log("before request");
var req = https.request(options,
function(response) {
// Continuously update stream with data
console.log("inside request");
response.on('data', function(data) {
console.log('Got Data'+data);
body += data;
});

response.on('end', function() {
console.log('now ending...');

});
response.on('error', function() {
console.log('got error');

});
}
);
console.log("after request"+queryData);

var output1 = req.write(queryData);
req.on('error', function(e)  {
console.log('got error');
  console.error(e);
});
console.log("Done" +output1);
req.end();
}
var checkConnection = function(retryInMilliseconds) {
    setTimeout(function() {
    console.log("Now running test");
    test();
    checkConnection(retryInMilliseconds);
    }, retryInMilliseconds);
  }

checkConnection(RETRY_INTERVAL);


I can see the requests in ACCESS LOG on central server which means the central server is getting requests. But somehow  callback function is not getting executed as expected.

I have been struggling a lot for few days. I removed node and installed it again, but no luck.

I appreciate all your time in helping solve this one.

Go Up