我正在尝试使用 axios 与代理服务器进行https调用:
const url = "https://walmart.com/ip/50676589"
var config = { proxy: { Host: proxy.ip, port: proxy.port } }
axios.get(url, config)
.then(result => {})
.catch(error => {console.log(error)})
我使用的代理服务器都在美国,非常匿名,支持HTTP和HTTPS。
我收到此错误:
{错误:写EPROTO 140736580649920:错误:140770FC:SSL例程:SSL23_GET_SERVER_HELLO:未知协议:../ deps/openssl/openssl/ssl/s23_clnt.c:794:
为了确保问题是axios而不是代理,我试过这个:
curl -x 52.8.172.72:4444 -L' https://www.walmart.com/ip/50676589 '
这完全正常。
如何配置axios以使用代理和https URL?
试试这个。这对我有用。
第一
npm install axios-https-proxy-fix
然后
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});
}
如果使用https代理,则需要支持Axios https代理支持。尝试使用http通过[httpsProxyAgent][1]
传递代理。
var axios = require('axios');
let httpsProxyAgent = require('https-proxy-agent');
var agent = new httpsProxyAgent('http://username:[email protected]:port');
var config = {
url: 'https://google.com',
httpsAgent: agent
}
axios.request(config).then((res) => console.log(res)).catch(err => console.log(err))
或者,有一个Axios的分支包含这个: axios-https-proxy-fix 但我建议第一种方法来确保最新的Axios更改。
尝试在URL中明确指定端口:
const url = "https://walmart.com:443/ip/50676589"
如果您还需要HTTPS-over-HTTP隧道,您将在 本文中找到解决方案 。
希望这可以帮助,
一月
这个错误是因为axios试图通过https代理您的请求(它从您的网址获取),有这张票跟踪它: https://github.com/axios/axios/issues/925