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

Request to HTTPS with HTTP proxy fails #925

Closed
kparkov opened this issue May 30, 2017 · 52 comments
Closed

Request to HTTPS with HTTP proxy fails #925

kparkov opened this issue May 30, 2017 · 52 comments
Projects

Comments

@kparkov
Copy link

@kparkov kparkov commented May 30, 2017

Summary

Trying to do a HTTPS request with a HTTP proxy fails.

const req = await axios({
  url: 'https://somedomain.com',
  proxy: {
    host: '89.151.146.7',
    port: 6060,
    auth: {
      username: 'myname',
      password: 'mypass',
    },
  },
});

Results in:

Error: write EPROTO 140736379442112:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:../deps/openssl/openssl/ssl/s23_clnt.c:794

The problem is already described by @chovy in this ticket, which ended up closed as OP did not have the same problem: #662

@chovy says:

I still have this issue not being able to hit an https url with an http proxy. I can do it fine in request and also in curl from shell. Something not working with axios. I get an EPROTO error.

### Context

  • axios version: v0.16.1
  • Environment: node v7.10.0, Mac OSX Sierra
@gigachel
Copy link

@gigachel gigachel commented May 31, 2017

I'm having the same problem of https request over proxy. I do not want to move to request.js.

return axios({
  url: 'https://site.com',
  proxy: {
       host: 'proxy.xxxxxx.com',
       port: 3128
   }
})

Result:
Error: write EPROTO 139800246822688:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:../deps/openssl/openssl/ssl/s23_clnt.c:794

request.js and curl in this situation works well.

Context

  • axios version: v0.16.1
  • Environment: node v6.9.5, CentOS release 6.8 (Final)
@Khaledgarbaya
Copy link
Collaborator

@Khaledgarbaya Khaledgarbaya commented Jun 15, 2017

Me and a colleague of mine identified the problem, a PR should be coming soon

@Khaledgarbaya
Copy link
Collaborator

@Khaledgarbaya Khaledgarbaya commented Jun 15, 2017

the PR is here #959

@mpcen
Copy link

@mpcen mpcen commented Jul 26, 2017

Same issue here: Requesting https resources behind an http proxy.

axios.get('https://resources.json', {   
   proxy: {
      host: 'http://my.proxy.com',
      port: 12345
   }
})
   .then(() => {})
   .catch(() => {});

Result:
Error: getaddrinfo ENOTFOUND http://my.proxy.com http://my.proxy.com:12345

@kunokdev
Copy link

@kunokdev kunokdev commented Sep 7, 2017

Any progress on this so far?

@Meg4mi
Copy link

@Meg4mi Meg4mi commented Sep 8, 2017

Same problem here.

Any news ?

@kunokdev
Copy link

@kunokdev kunokdev commented Sep 9, 2017

My problem was not related to proxies tho, I had to send GET request to https domain which wasn't certified. In curl inside linux terminal, solution was to use -k or --insecure flag. I couldn't find Axios solution tho, but with request lib I done it like so; might give you idea:

const agentOptions = {
    host: '10.100.0.10',
    port: '443',
    path: '/',
    rejectUnauthorized: false,
  }

const agent = new https.Agent(agentOptions)
request({
      url: 'https://10.100.0.10/myUncertifiedTargetUrl',
      method: 'GET',
      agent,
    }, (err, resp, body) => {
...
@mistermoe
Copy link

@mistermoe mistermoe commented Sep 25, 2017

Feel free to use this until they get #959 merged.

@PedramMarandi
Copy link

@PedramMarandi PedramMarandi commented Sep 26, 2017

Same here, btw @mistermoe's PR works fine

@sneko
Copy link

@sneko sneko commented Oct 31, 2017

@mistermoe I just left work without making it succeeded :(

I use this package : https://github.com/Yoctol/messaging-apis/tree/master/packages/messaging-api-messenger

And if I replace "axios" by yours, the following error disappears:
"Error: write EPROTO 139800246822688:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:../deps/openssl/openssl/ssl/s23_clnt.c:794"

But I have something like:
"Error: getaddrinfo EAI_AGAIN"

I notice that the Messenger plugin makes requests like that:
`
let client = axios.create({ ... });

client.get('...')
`

Did you succeed by this way or not directly by Axios "request" function?

Thanks!

EDIT: Another one having this issue:
#959 (comment)

@cur3n4
Copy link

@cur3n4 cur3n4 commented Nov 1, 2017

Any chance of merging this? Could we leverage the newly added config.transport to avoid this issue?

@skuarch
Copy link

@skuarch skuarch commented Dec 6, 2017

ups, same problem here!

@Sitronik
Copy link

@Sitronik Sitronik commented Jan 10, 2018

Unfortunately, this pull request doesn't merged, but I fixed this issue https://github.com/Sitronik/axios

@jan-molak
Copy link

@jan-molak jan-molak commented Jan 24, 2018

Had a similar issue recently, my solution was to use an HTTPS-over-HTTP tunnel, specify port 443 explicitly in the URL and disable automatic proxy detection in axios:

import axios, { AxiosInstance } from 'axios';
import * as tunnel from 'tunnel';

const tunnel = tunnel.httpsOverHttp({
    proxy: {
        host: 'proxy.mycorp.com',
        port: 8000,
    },
});

const httpClient: AxiosInstance = axios.create({
    baseURL: 'https://some.api.com:443',
    httpsAgent: tunnel,
    proxy: false,
});

More about the solution in this article.

Hope this helps,
Jan

@Sitronik
Copy link

@Sitronik Sitronik commented Jan 24, 2018

@jan-molak My fix is easy to use:

  1. npm install axios-https-proxy-fix
  2. Then
import axios from 'axios-https-proxy-fix'; 

const proxy = {
  host: 'some_ip',
  port: some_port_number,
  auth: {
    username: 'some_login',
    password: 'some_pass'
  }
};

async someMethod() {
  const result = await axios.get('some_https_link', {proxy});
}
@b4hand
Copy link

@b4hand b4hand commented Jan 25, 2018

@jan-molak's solution worked for me as well. It would really be nice to not have to force the port number on the url though.

@Alexis374
Copy link

@Alexis374 Alexis374 commented Jan 28, 2018

@jan-molak @Sitronik I tried your solution but get Error: socket hang up.
What I want is see how the request go through charles,so I open charles,and set proxy to {host:'127.0.0.1',port:8888} in my code. I don't know whether it is suitable to use your solution

@astappiev
Copy link

@astappiev astappiev commented Feb 23, 2018

Any chance to be included in 0.19.0?

@emilyemorehouse
Copy link
Member

@emilyemorehouse emilyemorehouse commented Feb 23, 2018

@astappev this definitely looks like it needs a fix ASAP. There's a lot of related issues and PRs that I need to sift through, but I'll add it to my 0.19.0 roadmap.

@redbearder
Copy link

@redbearder redbearder commented Jan 18, 2019

tried all solution and all failed base on axios 0.18
final solution :
install nginx module ngx_http_proxy_connect_module
then request https url via http proxy with request-promise

@chovy
Copy link

@chovy chovy commented Jan 18, 2019

@redbearder
Copy link

@redbearder redbearder commented Jan 18, 2019

You don’t need Nginx if you’re using request. Request handled proxies fine. - Anthony

On Jan 17, 2019, at 8:44 PM, redbearder @.***> wrote: tried all solution and all failed base on axios 0.18 final solution : install nginx module ngx_http_proxy_connect_module then request https url via http proxy with request-promise — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

Thank you for reply
I assume that people will send requests via single IP address as proxy gateway, that is what I will do
However request-promise catch a error "RequestError: Error: tunneling socket could not be established, code 400"
so I dont find solution from Node and then I try to fix it from Gateway side
and the solution comes out above

@YassienW
Copy link

@YassienW YassienW commented Jul 18, 2019

2 years later, still broken!!!

@chovy
Copy link

@chovy chovy commented Jul 18, 2019

@YassienW
Copy link

@YassienW YassienW commented Jul 18, 2019

Here's what i did for those who stumble upon this and still want to use axios:

const HttpsProxyAgent = require("https-proxy-agent"),
      axios = require("axios");

const httpsAgent = new HttpsProxyAgent({host: "proxyhost", port: "proxyport", auth: "username:password"})

//use axios as you normally would, but specify httpsAgent in the config
axios = axios.create({httpsAgent});

This will let you make https requests over an http proxy, simple and neat.

@pittersnider
Copy link

@pittersnider pittersnider commented Aug 28, 2019

Still having the same issue after 2 years.
Is someone working on this or can we join to contribute?

@klibs
Copy link

@klibs klibs commented Oct 8, 2019

Just ran into this issue myself. Hoping you guys can fix this at some point.
czl032405's solution of using proxy-agent worked for me.

@YassienW
Copy link

@YassienW YassienW commented Oct 8, 2019

According to the 0.19.0 release, this has been fixed. Since it obviously hasn't, a new issue should be opened

@axiac
Copy link

@axiac axiac commented Jan 15, 2020

This functionality is still broken in axios 0.19.
Version 0.19.0 fails with the message "Error: Protocol "http:" not supported. Expected "https:""
Version 0.19.1 fails with "Error: timeout of 1000ms exceeded". Increasing the timeout doesn't help. The proxy server expects a CONNECT request while axios sends a GET request.

rmp added a commit to nanoporetech/epi2me-api that referenced this issue Jan 29, 2020
byang183 referenced this issue in giggio/node-chromedriver Mar 6, 2020
Updated other deps.
Modernized code with async/await.
Updated node versions to only include
supported versions.
Closes #189
@axios axios locked and limited conversation to collaborators May 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
No open projects
0.19.0
  
Done
Linked pull requests

Successfully merging a pull request may close this issue.

None yet