在Corporate Proxy中,我设置了npm config设置。它正在工作。
npm config set https_proxy=http://username:password@proxy.example.com:8080
npm config set http_proxy=http://username:password@proxy.example.com:8080
npm config set proxy=http://username:password@proxy.example.com:8080
在Node.JS中,我使用了request
模块来调用HTTP请求。它不起作用。我收到以下错误。
throw new AssertionError(obj);
^
AssertionError [ERR_ASSERTION]: 3646 == 0
at ClientRequest.onConnect (C:\Users\Username\Documents\Workspace\node-course\web-server\node_modules\tunnel-agent\index.js:160:14)
at Object.onceWrapper (events.js:284:20)
at ClientRequest.emit (events.js:196:13)
at Socket.socketOnData (_http_client.js:492:11)
at Socket.emit (events.js:196:13)
at addChunk (_stream_readable.js:290:12)
at readableAddChunk (_stream_readable.js:271:11)
at Socket.Readable.push (_stream_readable.js:226:10)
at TCP.onStreamRead (internal/stream_base_commons.js:166:17)
[nodemon] app crashed - waiting for file changes before starting...
我的代码是
const url = 'https://jsonplaceholder.typicode.com/posts';
request({ url, json: true }, (error, { body } = {}) => {
console.log(error, body);
})
我使用npm config set ...
在NPM中添加的代理URL不起作用。
然后根据npm request
文档(https://github.com/request/request#controlling-proxy-behaviour-using-environment-variables),我借助(https://docs.cloudfoundry.org/cf-cli/http-proxy.html)在Windows Machine中添加了环境变量。这也行不通。