gpt4 book ai didi

node.js - 通过 https 代理 https 请求但返回 'unknown protocol:openssl ' 错误

转载 作者:太空宇宙 更新时间:2023-11-03 13:21:25 24 4
gpt4 key购买 nike

如果我通过“HTTP”代理请求“HTTP”地址,一切都很好

    const rq = require('request-promise'); 
try {
let res = rq({
url: 'http://xxxx',
timeout: TIME_OUT,
gzip: true,
proxy: 'http://112.25.60.32:8080'
});
res.then(res => {
console.log('res');
console.log(res);
}).catch(err => {
console.log(err);
});
} catch (error) {
console.log(error);
}

但是如果通过'https'代理请求'https'地址,它将返回'unknown protocol'

RequestError: Error: tunneling socket could not be established, cause=write EPROTO 101057795:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:openssl\ssl\s23_clnt.c:827:

try {
let res = rq({
url: 'https://ipinfo.io/', // https address
timeout: TIME_OUT,
gzip: true,
rejectUnauthorized: false,
proxy: 'https://149.56.109.24:3128' // https proxy
});
res.then(res => {
console.log('res');
console.log(res);
}).catch(err => {
console.log(err);
});
} catch (error) {
console.log(error);
}

一开始以为是代理地址的问题。但是相同的代理地址在 python 请求模块中工作正常

python code

import requests, os
os.environ['HTTP_PROXY'] = '112.25.60.32:8080'
os.environ['HTTPS_PROXY'] = '149.56.109.24:3128'
try:
text = requests.get('https://ipinfo.io/').text # request https address
except Exception as e:
print(e)
print('connect failed')
print(text)
# it works fine! {
"ip": "149.56.109.24:3128",
"hostname": "181.ip-158-69-206.net",
"city": "Montreal",
"region": "Quebec",
"country": "CA",
"loc": "45.5000,-73.5833",
"postal": "H3A",
"org": "AS16276 OVH SAS"
}
# The returned 'ip' information is the 'https' proxy address.

在 StackOverflow 中发现了类似的问题。有人回复说是端口问题。

Here is the link StackOverflow

但我认为这不是端口的问题,因为当我使用 fiddler 代理时,它有效!

Here is my configuration about fiddler

enter image description here

code (by fiddler)

try {
let res = rq({
url: 'https://ipinfo.io/',
timeout: TIME_OUT,
gzip: true,
rejectUnauthorized: false,
proxy: 'http://127.0.0.1:8888' // through fiddler
});
res
.then(res => {
console.log('res');
console.log(res); // it works!!
})
.catch(err => {
console.log(err);
});
} catch (error) {
console.log(error);
}

但是根据上面的代码,Proxy改成'149.56.109.24:3128'(没有fiddler)还是会报'unknown protocol:openssl\ssl\s23_clnt.c:827'的错误

那么到底出了什么问题呢?我没有解决。

最佳答案

   proxy: 'https://149.56.109.24:3128' //  https proxy

HTTP 代理将处理 HTTP 和 HTTPS。 HTTPS 的处理方式是直接连接到 HTTP 代理,发出 CONNECT 请求以建立到服务器的隧道,然后将连接升级到该隧道内的 TLS - 这会产生端到端的 HTTPS。

您配置的是通过 HTTPS 访问代理本身,本质上是在 HTTPS 隧道内请求 HTTPS。这很可能不受代理支持,即使用 http:// 访问代理而不是 https://

关于node.js - 通过 https 代理 https 请求但返回 'unknown protocol:openssl ' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51439768/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com