Skip to content Skip to sidebar Skip to footer

How To Use Axios With A Proxy Server To Make An Https Call?

It's basically the same question here. I'm using a browser. The following code is compiled by webpack. I tried this: const axios = require('axios'); var res = await axios.get('htt

Solution 1:

There is an open issue on axios's github page.

The issue is labeled as bug from 31 Mar and is not resolved yet.

So it seems you are not cursed, just a bug in axios.

You may add your details to that thread in order to dev team prioritize this issue.

In case you cannot wait for this issue to be resolved, you may consider using fetch API like @Sumi Straessle proposed in the comments.

Solution 2:

if you want to use axios and work-around the issue then consider using https-proxy-agent for proxy agent as mentioned in link

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

Solution 3:

axios's config.proxy is Node.js only. I think it is meaningless in browsers.

You can check lib/adapters/xhr.js and will find nothing related to proxy there.

Solution 4:

If you are trying to access an HTTPS URL by an HTTP proxy, you need to create an HTTPS-HTTP tunnel.

I found the solution for this issue in this post: https://janmolak.com/node-js-axios-behind-corporate-proxies-8b17a6f31f9d. Now it works perfectly!

Post a Comment for "How To Use Axios With A Proxy Server To Make An Https Call?"