Skip to content

https.request() can't connect to a website (ETIMEDOUT) but curl can #11694

Closed
@sryze

Description

@sryze

I'm trying to make a get request to a website over HTTPS but it always fails with ETIMEDOUT. Here is my code:

const https = require('https');

var req = https.get('https://www.hertz.com/rentacar/reservation/#vehicle', (res) => {
  console.log('get ok');
});

req.on('error', (error) => {
  console.error(error);
});

Output:

$ node test.js
{ Error: read ETIMEDOUT
    at exports._errnoException (util.js:1029:11)
    at TLSWrap.onread (net.js:575:26) code: 'ETIMEDOUT', errno: 'ETIMEDOUT', syscall: 'read' }

Fetching the same URL with curl works fine:

$ curl https://www.hertz.com/rentacar/reservation/\#vehicle
<!doctype html>
... the rest of the page follows ...

I searched a lot but could not find a working fix. I've tried passing secureProtocol: 'TLSv1_2_method' in request options (as the site uses TLS v1.2) as well as TLSv1_2_client_method and TLSv1_2_server_method

var req = https.request({
  url: 'https://www.hertz.com/rentacar/reservation/#vehicle',
  method: 'GET',
  secureProtocol: 'TLSv1_2_method'
}, (res) => {
  console.log('get ok');
});

but that didn't help, though it resulted in another error:

$ node test.js
{ Error: connect ECONNREFUSED 127.0.0.1:443
    at Object.exports._errnoException (util.js:1029:11)
    at exports._exceptionWithHostPort (util.js:1052:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1093:14)
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 443 }
  • Version: v7.7.1
  • Platform: Darwin pc.local 16.4.0 Darwin Kernel Version 16.4.0: Thu Dec 22 22:53:21 PST 2016; root:xnu-3789.41.3~3/RELEASE_X86_64 x86_64
  • Subsystem: https

Metadata

Metadata

Assignees

No one assigned

    Labels

    httpsIssues or PRs related to the https subsystem.invalidIssues and PRs that are invalid.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions