Proxy Port logo
如何 操作指南 > 如何为 Axios 设置代理

如何为 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 设置代理而不是自己拍摄,您需要执行以下操作:
  1. 安装 https-proxy-agent

    npm i https-proxy-agent
            
  2. 使用 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);
})();


            
        
抓取代理
了解更多