1 proxy request ssl-certificate node.js axios
我试图从共享托管服务器请求第三方服务器的 API,所以我没有 root 访问权限,并收到此错误,但是当我在失眠中尝试它时,它正常工作,显然是由于它的原因代理或证书。已经尝试httpsAgent: new https.Agent({ rejectUnauthorized: false })在 axios 请求选项中使用,并尝试过 NODE_TLS_REJECT_UNAUTHORIZED=0,但没有成功。我没有粘贴证书和服务器信息信息,但如果有必要,我可以分享它。这就是我提出请求的方式:
async appInfo(){
var config = {
method: 'get',
url: `${this.url}/api/v2/me/shipment/app-settings`,
headers: {
'Accept': 'application/json',
'Authorization':`Bearer ${this.bearer}`,
'User-Agent': this.user_agent
}
};
var response = await axios(config)
console.log(JSON.stringify(response.data));
}Run Code Online (Sandbox Code Playgroud)
小智 5
我不知道你是否已经修复了它,但无论如何我都会回答。它可能对其他人有帮助。这是我在这里找到的解决方案:https://github.com/axios/axios/issues/1650
查看您的代码,您应该在标头之外设置代理配置。像那样:
// At instance level
const instance = axios.create({
httpsAgent: new https.Agent({
rejectUnauthorized: false
})
});
instance.get('https://something.com/foo');
// At request level
const agent = new https.Agent({
rejectUnauthorized: false
});
axios.get('https://something.com/foo', { httpsAgent: agent });
Run Code Online (Sandbox Code Playgroud)
警告:这可能是安全故障,只有当您确实信任共享数据的位置时才使用它。
干杯。
| 归档时间: |
|
| 查看次数: |
7619 次 |
| 最近记录: |