如何为 Axios 设置代理
如果您遇到此错误,本文将对您有所帮助:
cause: Error: write EPROTO 139802847135616:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332:
at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:98:16) {
errno: -71,
code: 'EPROTO'
开门见山。
要为 Axios 设置代理而不是自己拍摄,您需要执行以下操作:
要为 Axios 设置代理而不是自己拍摄,您需要执行以下操作:
- 安装
https-proxy-agent
包npm i https-proxy-agent
- 使用
httpsAgent
设置代理
const axios = require('axios');
const HttpsProxyAgent = require('https-proxy-agent');
const url = "https://example.com";
const config = {
httpsAgent: new HttpsProxyAgent('http://yourproxyserver.com:8080'),
};
(async() => {
let response = await axios.get(url, config);
console.log(response?.data);
})();