I have a simple Node test script that sends a POST request via https that works perfectly on one Ubuntu box, but fails on a similarly configured (but older version) box. Here's the script:
const https = require('https');
const data = 'artist=Betty2%20Hutton2&title=It%20Is%20A%20Good%20Day';
const options = {
hostname: 'my_server.com',
port: 443,
path: '/path/to/script.php',
method: 'POST',
headers: {
'Content-Type': 'text/plain',
'Content-Length': data.length
}
};
const req = https.request(options, function(res) {
console.log('status code is: ' + res.statusCode);
res.on('data', function(d) {
process.stdout.write(d)
});
req.on('error', function(error) {
console.error(error)
});
});
req.write(data);
req.end();
I can get it to work on one Ubuntu box, but on the other one (the one I really need it to work on), I get this error:
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^ Error: ECONNREFUSED, Connection refused
at Socket._onConnect (net.js:601:18)
at IOWatcher.onWritable [as callback] (net.js:186:12)
From the box this script fails on, I can ping the host (which is running Apache2), and I can connect to the host + port via telnet, so I know the receiving machine is listening. I can't figure out why this won't work.
Any suggestions you have for diagnosing this will be GREATLY appreciated.
EDIT:
I also tried sending POST data using the request module. My code is:
var request = require('request');
var BASE = 'https://my_server.com/path/to/script.php';
var data = 'artist=Betty2%20Hutton2&title=It%20Is%20A%20Good%20';
request({
method: 'POST',
uri: BASE,
form: data
}, function(e,r,body) {
console.log('ERROR' + e);
//console.log('RESPONSE' + r.statusCode);
console.log('BODY'+body);
}).start();
This results in:
ERRORError: socket hang up
EDIT 2:
I'm starting to think it's an SSL problem. If I run this:
curl -I http://a_non_SSL_site.com/
I get a 200 result code and the other info you'd expect. However, if I curl an https site, I get this back:
curl: (35) error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version
Am I correct that this IS an SSL problem and, if so, how do I fix it?
Thanks.
EDIT 3
Just in case anyone stumbles upon this in the future, it WAS an SSL problem or, more precisely, a TLS problem. Upgrading OpenSSL fixed the issue.
question from:
https://stackoverflow.com/questions/65925804/econnrefused-error-on-one-box-but-not-on-another