axios: Request to HTTPS with HTTP proxy fails

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: https://github.com/mzabriskie/axios/issues/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

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 56
  • Comments: 52 (2 by maintainers)

Commits related to this issue

Most upvoted comments

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

Same issue… please merge!

Same issue here

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

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.

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)

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

@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});
}

2 years later, still broken!!!

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

@jan-molak 's fix saved my day. +1 to merging the PR.

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)
    })

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.

@emilyemorehouse, do you have any estimation when it will be released? The PR #959 solve critical part of the issue, other issues like proxying redirections and so can be improved later. The changes in #959 are pretty simple and can be published in just few minutes.

Any chance to be included in 0.19.0?

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.

Another +1 to merging this!!

Ran into the same problem.

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

fixed the problem for me.

@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.

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

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

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

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.

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
});

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