axios: Axios proxy is not working.
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:
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
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 11
- Comments: 21
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 :
And also with the httpsAgent param :
None of them work.
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):tldr: setup
httpsAgent
and (!) setproxy: false
.none of these shite solutions work!
i did 3 things that got it working.
first 2 didn’t help without the last one.
Let me make some conclusions,
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.https-proxy-agent
, better to disable the proxy byproxy: false
. See @kraiz’s comment.@nsharma1989 Sounds frustrating. I can’t help beyond my own success using node-tunnel with axios. I don’t know if a server can force using a signed certificate or not. I was reading about self-signed certificates which need to be shared between the client and server.
I assume you placed rejectUnauthorized: false on the agent configuration
Sorry I can’t be more help.