0
我使用request.defaults(..)
- 除其他外 - 为我的请求设置自定义http代理(设置maxSockets
和keepAlive
)。Node.js - 请求:指定自定义代理,可以处理http和https
const agent = new http.Agent({
keepAlive: true,
maxSockets: 42
})
const requestWithCustomAgent = request.defaults({
agent,
json: true,
headers: {
'User-Agent': 'amazing agent'
}
})
当访问与方案中的URL https
这个错误与Error: Protocol "https:" not supported. Expected "http:"
。反之亦然https.Agent
和计划http
。
有什么办法可以“告诉”请求处理与一个代理http
请求和https
与另一个?
一个可以投资一些麒麟血,做黑暗魔法,如:
if(url.startsWith('https') {/* use on agent */} else { /* use the other */}
但是,这感觉hack'ish。
是一样的东西:
const requestWithCustomAgent = request.defaults({
agents: {
'http': httpAgent,
'https': httpsAgent
},
json: true,
headers: {
'User-Agent': 'amazing agent'
}
})
可能吗?
帮助表示赞赏;)
听起来更像是OP是什么寻找 – James
不错,所以限制(如maxSockets等)将适用于“每个方案”的基础上?并且例如http代理只会忽略“cert”,“key”等选项。 –
@FlorianBarth正确。 – robertklep