TypeError: Expected the `options.agent` properties to be `http`, `https` or `http2`, got `options`
TypeError: Expected the `options.agent` properties to be `http`, `https` or `http2`, got `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
如何修复此错误?
使用node的GOT库如何设置代理?
变化:
got(..., {
agent: tunnel.httpsOverHttps(...)
});
收件人:
got(..., {
agent: {
https: tunnel.httpsOverHttps(...)
}
});
参考文献:
我正在尝试在我的 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
如何修复此错误?
使用node的GOT库如何设置代理?
变化:
got(..., {
agent: tunnel.httpsOverHttps(...)
});
收件人:
got(..., {
agent: {
https: tunnel.httpsOverHttps(...)
}
});
参考文献: