我换用 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
}