question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Axios proxy is not working.

See original GitHub issue

Describe the bug I have installed anyProxy 3rd party proxy ( http://anyproxy.io/en/#install ) When I type anyproxy in my command line then my proxy starts on http://localhost:8001 and I have also preview of proxy status on http://localhost:8002.

On the Frontend site, I’m using axios like:

axios
      .get("https://randomuser.me/api/?results=50", {
        proxy: {
          host: "http://localhost",
          port: 8001
        }
      })
      .then(response => {
        const data = response.data.results;
        this.setState({ data });
      })
      .catch(error => {
        console.log(error);
      });

Here is a simplified version of this: https://codesandbox.io/s/j35zl05lk5

But the request is omitting proxy and is sent directly: image

It behaves like the axios proxying functionality would not be even working.

I also tried stuff like:

let httpsProxyAgent = require("https-proxy-agent");
var agent = new httpsProxyAgent("http://localhost:8001");
...
 axios
      .get("https://randomuser.me/api/?results=50", {
        httpAgent: agent
      })
      .then(response => {
        const data = response.data.results;
        this.setState({ data });
      })
      .catch(error => {
        console.log(error);
      });

But it gives me the same result as the previous one. Also tried npm dependency called “axios-https-proxy-fix”, but with the same result.

Expected behavior Proxying request to the proxy server.

Environment:

  • Axios Version “axios”: “0.18.0”,
  • OS: Win 10
  • Browser Chrime
  • Browser Version 73.0.3683.86

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:11
  • Comments:21

github_iconTop GitHub Comments

17reactions
SwiToolcommented, May 7, 2019

I can confirm. Full post on https://stackoverflow.com/questions/55981040/axios-https-request-over-a-proxy

I tried the proxy param, which is apparently not supported in browser, but at least I tried :

const axios = require('axios');

var res = await axios.get('https://api.ipify.org?format=json', {
    proxy: {
        host: 'proxy-url',
        port: 80,
        auth: {username: 'my-user', password: 'my-password'}
    }
});
console.log(res.data); // gives my ip and not the proxy's one

And also with the httpsAgent param :

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

var agent = new HttpsProxyAgent('http://my-user:my-pass@proxy-url:port');
var res = await axios.get('https://api.ipify.org?format=json', {
    httpsAgent: agent,
});
console.log(res.data); // gives my ip and not the proxy's one

None of them work.

16reactions
kraizcommented, Dec 19, 2019

I was able to make requests to some servers but not all. Seems like it depends on the servers cipher suites. For all servers with just cipher suites beginning with ECDHE_ the request failed.

Following the axios’ code we need to make sure that this if expression is false: http.js#L100 . I fixed the problem with this axios configuration (applying it to @habmukandu code above):

const HttpsProxyAgent = require('https-proxy-agent');

const const axiosDefaultConfig = {
    baseURL: 'https://jsonplaceholder.typicode.com/posts',
    proxy: false,
    httpsAgent: new HttpsProxyAgent('http://142.93.165.82:8080')
};

const axios = require ('axios').create(axiosDefaultConfig);
axios.get('42')
    .then(function (response) {
        console.log('Response with axios was ok: ' + response.status);
    })
    .catch(function (error) {
        console.log(error);
    });

tldr: setup httpsAgent and (!) set proxy: false.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The proxy is not working. · Issue #4369 · axios/axios - GitHub
The original meaning is: There is a program written using axios because the system has set up a proxy, so it cannot work....
Read more >
Axios post request with proxy isn't working - Stack Overflow
Their docs are deprecated (using response package) so I need to use axios. Right now link is clicked and it just loads forever...
Read more >
Nuxt Axios Proxy not working on Forge - Laracasts
I'm struggling since yesterday to make nuxt-axios proxy works. Locally everything is working fine but on the server the axios calls are not...
Read more >
How to use a Proxy with Axios and Node JS - ScrapingBee
Rotating proxies with requests​​ You can do this by simply defining an array of proxies and using a random proxy with each new...
Read more >
How to Use a Proxy with axios - Cobalt Intelligence
A short video showing an example of how to use a proxy with axios (https://github.com/axios/axios). You will need https-proxy-agent ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found