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 · 45 comments

Comments

Projects
@kparkov
Copy link

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Collaborator

Khaledgarbaya commented Jun 15, 2017

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

@Khaledgarbaya

This comment has been minimized.

Copy link
Collaborator

Khaledgarbaya commented Jun 15, 2017

the PR is here #959

@mpcen

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

kunokdev commented Sep 7, 2017

Any progress on this so far?

@Meg4mi

This comment has been minimized.

Copy link

Meg4mi commented Sep 8, 2017

Same problem here.

Any news ?

@kunokdev

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

mistermoe commented Sep 25, 2017

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

@PedramMarandi

This comment has been minimized.

Copy link

PedramMarandi commented Sep 26, 2017

Same here, btw @mistermoe's PR works fine

@sneko

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

cur3n4 commented Nov 1, 2017

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

@skuarch

This comment has been minimized.

Copy link

skuarch commented Dec 6, 2017

ups, same problem here!

@Sitronik

This comment has been minimized.

Copy link

Sitronik commented Jan 10, 2018

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

@jan-molak

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

astappiev commented Feb 23, 2018

Any chance to be included in 0.19.0?

@emilyemorehouse

This comment has been minimized.

Copy link
Member

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.

@camueller

This comment has been minimized.

Copy link

camueller commented Jun 8, 2018

@Sitronik that works for me thanks - please merge!
However the proxy settings does not seem to be read from environment variables (http_proxy / https_proxy) but have to be specified as part of AxiosRequestConfig.

@necevil

This comment has been minimized.

Copy link

necevil commented Jul 28, 2018

+1 Still using work arounds mentioned above but would love to see this work out of the box.

@fractalzombie

This comment has been minimized.

Copy link

fractalzombie commented Aug 14, 2018

+1 When you fix this? But we need no_proxy too...

@Makoehle

This comment has been minimized.

Copy link

Makoehle commented Aug 22, 2018

@Sitronik please add PR. Your package axios-https-proxy-fix works just fine. axios.defaults.proxy = {host: ip, port: port}

@m2jobe

This comment has been minimized.

Copy link

m2jobe commented Aug 24, 2018

Still an issue, would use that package but its many commits behind? Would that be a non issue :S

@Makoehle

This comment has been minimized.

Copy link

Makoehle commented Aug 27, 2018

would use that package but its many commits behind?

Same for me while waiting for that change I'm going for node-fetch + httpsProxyAgent + bluebird. Works fine.

@m2jobe

This comment has been minimized.

Copy link

m2jobe commented Aug 27, 2018

@Makoehle

Hey I ended up getting it to work, try export http and https to "" on your terminal

export http_proxy="" && export https_proxy=""

@Makoehle

This comment has been minimized.

Copy link

Makoehle commented Aug 28, 2018

Thank you I know about env variables. I tried everything. My guess is it has to do with #1207

@lderzhavets

This comment has been minimized.

Copy link

lderzhavets commented Aug 30, 2018

Waiting for merge too. Why it is so long?

@emilyemorehouse

This comment has been minimized.

Copy link
Member

emilyemorehouse commented Aug 30, 2018

#959 was merged and is available in 0.19.0-beta.1

@czl032405

This comment has been minimized.

Copy link

czl032405 commented Sep 7, 2018

I can not solve it out in 0.19.0-beta.1, but I fixed like this

// default axios usage
import * as ProxyAgent from "proxy-agent";
const proxyAgent = new ProxyAgent(process.env.HTTPS_PROXY);  // http://127.0.0.1:1080
Axios.defaults.httpsAgent = proxyAgent;
Axios.defaults.proxy = false;

// google api usage
const Sheets = google.sheets({
    version: "v4",
    auth: key,
    httpsAgent: /dev/.test(process.env.NODE_ENV) ? proxyAgent : false,
    proxy: false
});
@Khaledgarbaya

This comment has been minimized.

Copy link
Collaborator

Khaledgarbaya commented Sep 7, 2018

0.19.0-beta.1 should fix the issue, I am closing the issue and feel free to create a new one if anyone still having the issue

0.19.0 automation moved this from To do to Done Sep 7, 2018

@necevil

This comment has been minimized.

Copy link

necevil commented Sep 7, 2018

@Khaledgarbaya I am still having this issue with 0.19.0-beta.1
My question is what should my proxy request look like (and how does the isHttps flag work?).

I assumed that for HTTPS over HTTP I would simple set the http url / port for the proxy like this:

axiosRequestOptions.proxy = {
            host: '192.0.01',
            port: '8888',
            // isHttps: true, ?
        }

That being said the above still fails so I am wondering if it is a configuration / documentation issue where my structuring of the proxy property / object is the cause.

@Sitronik

This comment has been minimized.

Copy link

Sitronik commented Sep 8, 2018

@necevil
host: '192.0.01'

@bidhan-a

This comment has been minimized.

Copy link

bidhan-a commented Sep 24, 2018

The 0.19.0-beta.1 still does not work. I kept getting Request failed with status code 400. Wasted a lot of time on this. Switched to the request library and it worked like a charm on the first try.

@mikkqu

This comment has been minimized.

Copy link

mikkqu commented Oct 7, 2018

Ran into the same problem.

const axios = require('axios-https-proxy-fix')

fixed the problem for me.

@mrodrig

This comment has been minimized.

Copy link

mrodrig commented Oct 9, 2018

After updating to 0.18.0 this seems to be working for me. I had to specify the following options for my use case though:

axios.get('<some_url_on_corporate_intranet>', {
        proxy: false,
        httpsAgent: https.Agent({
            rejectUnauthorized: false // Allows the use of self-signed certificates (not recommended)
    })
@redbearder

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

chovy commented Jan 18, 2019

@redbearder

This comment has been minimized.

Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment