node.js socket hang up over https

2019-04-16 08:10发布

问题:

We are trying to get node to use a ssl based api on another machine and it's failing with a socket hang up error. I'm putting the code below. Basically, on one machine we have a asp.net web api based api set up to accept a request, and on another we have a tomcat spring mvc based api accepting requests. Both apis work with fiddler, postman, other sites sending identical requests, however with node sending to the tomcat site, we get an immediate socket hangup error. We're really struggling trying to figure out what is wrong. So it will work correctly with one ssl based url, but fail with the other, and we've confirmed both sites work. The code is below. Is there something we're missing?

app.post('/site/app/getvalue', function(req, res){
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
console.log("Request: ");
console.log(req.body);

var options = {
    method: 'post',
    body: req.body,
    json: true,
    //url: 'https://X.X.X.X/getvalue/',
    url : 'https://X.X.X.X:8443/getvalue/',
    rejectUnauthorized: false,
    headers: { 'Content-Type' : 'application/json'}
};

request(options,
    function (error, response, body) {
        if (!error && response.statusCode == 200) {
            console.log("Response: ");
            console.log(body);
            console.log("Transaction Count: " + body.TransactionCount);
            res.send(body);
        }
        else {
            console.log("ERROR: " + error);
            res.send(500);
        }
    }
);
});

We get: ERROR: Error: socket hang up