0

I am trying out a NodeJS sample file from a tutorial as I am new to NodeJS but I just can't make it work. I get an error when I run below code:

var https = require("https");
var fs =    require("fs");

var options = {
    hostname: "en.wikipedia.org",
    port: 443,
    path: "/wiki/George_Washington",
    method: "GET",
}

var req = https.request(options, function(res){ });

req.on('error', function(e) {
    console.log(`here comes the error ${e}`);
});

I get the following error:

 here comes the error:
 Error:101057795:error:140770FC:SSLroutines:SSL23_GET_SERVunknownprotocol:openssl\ssl\s23_clnt.c:794:

I am clueless, I appreciate your help and insight :)

Update: Code had to be modified to go through a proxy server. I posted the solution and findings.

4
  • Try to curl the request, and see what headers are being sent Commented Dec 15, 2016 at 3:33
  • One thing you're missing is req.end() since you're using https.request() instead of https.get(). Commented Dec 15, 2016 at 3:55
  • Also, what version of node are you using? Commented Dec 15, 2016 at 3:55
  • Hi @mscdex, I tried adding req.end() to my code and it did not resolve the issue. It must be our company policies that blocks the connection. I am using Node version 6.5.0 Commented Dec 15, 2016 at 4:32

2 Answers 2

1

I solved the issue. Here is a summary of the problem and the solution that worked for me.

I ran this code in another network and it worked fine. So I realized the issue is that I am running the code behind our corporate web proxy and I need to modify my code to go through the proxy system instead of making a direct connection to target web server. I tried to install https-proxy-agent module but it failed to install. Again, because I am behind the proxy system. There is a npm config settings file named .npmrc file which can be found under C:/users/[YOUR_USER]. I added below configs to .npmrc to be able to install new packages as was advised Here.

proxy = http://172.26.128.35:3128/
https_proxy = http://172.26.128.35:3128/
strict-ssl = false
ca = null
registry = http://registry.npmjs.org/

Finally I modified my code as below to make it go through and the proxy system and voila~, It worked like a charm. If you encountered this issue, I hope this helps.

var https = require("https");
var fs =    require("fs");
var HttpsProxyAgent = require('https-proxy-agent');
var proxy = 'http://172.26.128.35:3128';
var agent = new HttpsProxyAgent(proxy);

var options = {
    hostname: "en.wikipedia.org",
    port: 443,
    path: "/wiki/George_Washington",
    method: "GET",
    agent: agent
}

var req = https.request(options, function(res) {
  console.log(res.statusCode);
  res.on('data', function(d) {
    process.stdout.write(d);
  });
});
req.end();

req.on('error', function(e) {
    console.log(`here comes the error ${e}`);
});
Sign up to request clarification or add additional context in comments.

Comments

0

Have you tried this code?

var https = require("https");
var fs =    require("fs");

var options = {
    hostname: "en.wikipedia.org",
    port: 443,
    path: "/wiki/George_Washington",
    method: "GET",
}

var req = https.request(options, function(res) {
  console.log(res.statusCode);
  res.on('data', function(d) {
    process.stdout.write(d);
  });
});
req.end();

req.on('error', function(e) {
    console.log(`here comes the error ${e}`);
});

Works fine for me!

10 Comments

Maybe it could be a problem with your connect. Have you tried to do a webservice call using the curl method? Try to do a telnet in this website with 443 port.
I just tried you code and It does not work for me though, I get the same mentioned error. It is very strange.
try to do this in your prompt or shell: telnet en.wikipedia.org 443 and verify if you can stabilish connection
It took ages for me to enable telnet on my system and restart it, sorry for late reply. I tried telnet en.wikipedia.org 443 and it says "Access denied by security policy". I later try this code at home. I am just wondering, How is it that I can use a browser and go to wikipedi page over HTTPS protocol, but I cannot access it using Telnet or NodeJS ? What is the difference ? What am I missing ?
Telnet is a protocol used to stabilish connection with host in specified port. Using this tool you can verify if you have access for that.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.