如何解决TypeError:期望options.agent属性为http,https或http2,并获得options
我正在尝试在Node.js代码中设置代理。我正在使用npm的GOT库通过本地系统发出API请求。
我要执行的代码:
var tunnelingAgent = tunnel.httpsOverHttps({
proxy: {
host: 'rb-proxy-de.abc.com',port: 8080,proxyAuth : 'username:password',headers: {
'User-Agent': 'Node'
}
}
});
got({
'url':'https://services.odata.org/V4/OData/OData.svc/Products','method': "GET",'responseType': 'json'
},{agent : tunnelingAgent}).then((response) => {
console.log(response)
}).catch((err) => {
console.log(err.stack)
})
我得到的错误:
TypeError: Expected the `options.agent` properties to be `http`,`https` or `http2`,got `options`
at normalizeArguments (C:\Users\hck2kor\Documents\node practice\proxy\node_modules\got\dist\source\core\index.js:611:27)
at normalizeArguments (C:\Users\hck2kor\Documents\node practice\proxy\node_modules\got\dist\source\as-promise\core.js:34:31)
at got (C:\Users\hck2kor\Documents\node practice\proxy\node_modules\got\dist\source\create.js:104:39)
at Object.<anonymous> (C:\Users\hck2kor\Documents\node practice\proxy\proxycode.js:54:1)
at Module._compile (internal/modules/cjs/loader.js:955:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
at Module.load (internal/modules/cjs/loader.js:811:32)
at Function.Module._load (internal/modules/cjs/loader.js:723:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
at internal/main/run_main_module.js:17:11
如何解决此错误?
使用节点的GOT库时如何设置代理?
解决方法
更改:
got(...,{
agent: tunnel.httpsOverHttps(...)
});
收件人:
got(...,{
agent: {
https: tunnel.httpsOverHttps(...)
}
});
参考:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。