proxy and node-rest-client error : 'events.js:183 throw er;'

232 Views Asked by At

I've two questions but the most important is : Why the following code shows me nothing when tunnel: true and shows me an error when turned to false... but never any datas ?

The code :

let Client = require('node-rest-client').Client;
let options_proxy = {
    proxy: {
        host: "172.16.0.1",
        port: 3128,
        tunnel: false
    }
};

let connexion = new Client(options_proxy);

connexion.registerMethod("jsonMethod", "https://www.prevision-meteo.ch/services/json/seyssinet-pariset", "GET");
connexion.methods.jsonMethod(function (data, response) {
    // parsed response body as json object
    console.log(data);
    console.log('=====================================');
    console.log(`actuellement à ${data.city_info.name} il fait ${data.current_condition.condition}.`);
    // raw response
    console.log(response);
});

The error :

node index.js
events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: socket hang up
    at TLSSocket.onHangUp (_tls_wrap.js:1137:19)

More information : On a network with direct access, it works (showing me a city and a weather associated). On the network with proxy access, the proxy works (tested with Chrome and FF and Telnet) but the program is in error.

Any idea how to check deeper ? maybe an http rest server rather https ?

My second questions is : I've used CTRL+K to display my code, is that correct (some guys said they've to correct this on my post) ? more easy to answer I hope ;) Thanks

1

There are 1 best solutions below

0
On

It seems we've an HTTPS problem, and the workaround is to change the URL from HTTPS to HTTP.

connexion.registerMethod("jsonMethod", "https://www.prevision-meteo.ch/services/json/seyssinet-pariset", "GET");

However, it still a problem and I'm not able to diagnose it deeper. Maybe a bug or a proxy mysconfiguration.