Everything is fine if I request 'HTTP' address via 'HTTP' proxy
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);
}
But if request 'https' addrss via 'https' proxy, it will return '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);
}
At first I thought it was a problem with the proxy address. But the same proxy address works fine in python requests module
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.
A similar problem was found in StackOverflow. Someone replied that it is a port problem.
Here is the link StackOverflow
But I think this is not a problem about the port,because when I use proxy by fiddler, it works!
Here is my configuration about fiddler
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);
}
However, based on the above code, Proxy changed to '149.56.109.24:3128' (without fiddler) will still report 'unknown protocol:openssl\ssl\s23_clnt.c:827' error
So what went wrong? I have not solved it.