我想用 axios 通过远程代理去做一个请求,但是一直返回错误。
我换用 HttpsAgent 就可以,请问这是为啥?
import axios from "axios"; axios.get('https://www.google.com', { proxy: { protocol: 'https', host: 'xxx.yyy.com', port: '443', auth: { username: '123456', password: '123456' } }, }).then(r => { console.log(r.data) }).catch(e => { console.error(JSON.stringify(e)) })
{ "message":"read ECONNRESET", "name":"Error", "stack":"Error: read ECONNRESET\n at Function.AxiosError.from (file:///*/axios-test/node_modules/axios/lib/core/AxiosError.js:89:14)\n at RedirectableRequest.handleRequestError (file:///*/axios-test/node_modules/axios/lib/adapters/http.js:591:25)\n at RedirectableRequest.emit (node:events:527:28)\n at ClientRequest.eventHandlers.<computed> (*/axios-test/node_modules/follow-redirects/index.js:14:24)\n at ClientRequest.emit (node:events:527:28)\n at TLSSocket.socketErrorListener (node:_http_client:454:9)\n at TLSSocket.emit (node:events:527:28)\n at emitErrorNT (node:internal/streams/destroy:157:8)\n at emitErrorCloseNT (node:internal/streams/destroy:122:3)\n at processTicksAndRejections (node:internal/process/task_queues:83:21)", "config":{ "transitional":{ "silentJSONParsing":true, "forcedJSONParsing":true, "clarifyTimeoutError":false }, "adapter":[ "xhr", "http" ], "transformRequest":[ null ], "transformResponse":[ null ], "timeout":0, "xsrfCookieName":"XSRF-TOKEN", "xsrfHeaderName":"X-XSRF-TOKEN", "maxContentLength":-1, "maxBodyLength":-1, "env":{ "Blob":null }, "headers":{ "Accept":"application/json, text/plain, */*", "User-Agent":"axios/1.4.0", "Accept-Encoding":"gzip, compress, deflate, br" }, "proxy":{ "protocol":"https", "host":"xxx.yyy.com", "port":"443", "auth":"123456:123456" }, "method":"get", "url":"https://www.google.com" }, "code":"ECONNRESET", "status":null }
![]() | 1 naminokoe 2023-07-20 05:57:36 +08:00 via iPhone 还是润了舒服,不用配置这些乱七八糟的东西,什么都可以直连 |
![]() | 2 coderdusk 2023-07-20 08:35:01 +08:00 刚搜了一下,port 好像传的数字类型而不是字符串吧 |
![]() | 3 monster1priest OP @coderdusk 试过了,和这个没什么关系 |