5 精币
为什么用node使用代理访问http是正常的,但是访问https却不行报错 :AxiosError: Client network socket disconnected before secure TLS connection was established
按照网上说的增加了 httpsAgent : new https .Agent ({rejectUnauthorized : false })这个代码也不行.
同样的请求方式放在E里面是没问题的,感觉是自己哪里还没弄好.请教下大家.怎么办啊
以下是代码
const axios = require ('axios' );
const https = require ('https' );
axios .get ('http://getIp' , {
params : {
action : 'BEAPI' ,
number : 1 ,
}
}).then (response => {
const proxy = response .data .trim ();
const [proxyHost , proxyPort ] = proxy .split (':' );
// 设置代理配置
const proxyConfig = {
host : proxyHost ,
port : proxyPort ,
};
const instance = axios .create ({
proxy : proxyConfig ,
httpsAgent : new https .Agent ({rejectUnauthorized : false })
});
// const headers = {
// 'Content-Type': 'application/json; charset=utf-8',
// }
// const requestBody = {}
// const Url="http://xxx.com"
const Url = "https://xxx.com"
const headers = {
'Content-Type' : 'application/json' ,
}
const requestBody = {}
instance .post (Url ,requestBody ,{ headers : headers })
.then (response => {
console .log (response .data );
})
.catch (error => {
console .error (error );
});
})
.catch (error => {
console .error ('获取代理失败:' , error );
});
我来回答
回答提醒: 如果本帖被关闭无法回复,您有更好的答案帮助楼主解决,请发表至
源码区 可获得加分喔。
友情提醒: 本版被采纳的主题可在
申请荣誉值 页面申请荣誉值,获得
1点 荣誉值,荣誉值可兑换荣誉会员、终身vip用户组。
快捷通道: 申请荣誉值 →