Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sryze opened this issue Mar 5, 2017 · 2 comments
Closed

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

sryze opened this issue Mar 5, 2017 · 2 comments
Labels
https Issues or PRs related to the https subsystem. invalid Issues and PRs that are invalid.

Comments

@sryze
Copy link

sryze commented Mar 5, 2017

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
@sryze sryze changed the title https.get() can't connect to a website (ETIMEDOUT) but curl can https.request() can't connect to a website (ETIMEDOUT) but curl can Mar 5, 2017
@addaleax addaleax added the https Issues or PRs related to the https subsystem. label Mar 5, 2017
@addaleax
Copy link
Member

addaleax commented Mar 5, 2017

Fwiw this works when passing the curl User-Agent header, i.e.

https.get({
  host: 'www.hertz.com',
  path: '/rentacar/reservation',
  headers: {
    'User-Agent': 'curl/7.47.0'
  }
}, )

and conversely curl -A '' 'https://www.hertz.com/rentacar/reservation/#vehicle' times out, so I’m pretty sure it’s a server-side bug. :/

@silverwind
Copy link
Contributor

silverwind commented Mar 5, 2017

Yep, server issue. Can be reproduced without node:

$ curl -H 'User-Agent: curl' -v 'https://www.hertz.com/rentacar/reservation/#vehicle'
$ curl -H 'User-Agent: bad' -v 'https://www.hertz.com/rentacar/reservation/#vehicle'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
https Issues or PRs related to the https subsystem. invalid Issues and PRs that are invalid.
Projects
None yet
Development

No branches or pull requests

4 participants