问题描述
基本上是同样的问题.
我正在使用浏览器.以下代码由 webpack 编译.我试过这个:
I'm using a browser. The following code is compiled by webpack.I tried this:
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.
我也用相同的代码试过这个,但没有用:
I also tried this with the same code, but it did not work:
const axios = require('axios-https-proxy-fix');
然后,我尝试使用 httpsAgent:
Then, I tried with httpsAgent:
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.
这是一个错误吗?我是被诅咒了还是我在阅读文档时遇到了问题?
Is this a bug? Am I cursed or maybe do I have a problem reading the documentation?
推荐答案
该问题自 3 月 31 日起被标记为错误,尚未解决.
The issue is labeled as bug from 31 Mar and is not resolved yet.
看来你没有被诅咒,只是axios的一个bug.
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.
如果您等不及这个问题得到解决,您可以考虑使用 fetch API 就像@Sumi Straessle 在评论中提出的一样.
In case you cannot wait for this issue to be resolved, you may consider using fetch API like @Sumi Straessle proposed in the comments.
这篇关于如何使用带有代理服务器的 axios 进行 https 调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!