1

我正在使用 node-fetch 模块和 javascript 来处理 API 请求。下面是我的代码(只是一个示例 GET 操作)

var fetch = require('node-fetch');

const HttpsProxyAgent = require('https-proxy-agent');

    fetch('http://postalpincode.in/api/pincode/600042', {method: 'GET', agent: new HttpsProxyAgent('http://10.10.104.4:50683') })
    .then(resRaw=>{
    resRaw.toJson();
    })
    .then(resJson=>{
    console.log(resJson);
    })

但我收到以下错误。请帮我解决这个问题。我已经安装了 node-fetch、https-proxy-agent 模块。

FetchError: request to http://postalpincode.in/api/pincode/600042 failed, reason: socket hang up
at ClientRequest. (F:\johny\three projects\test-nodefetch\node_modules\node-fetch\lib\index.js:1345:11)
at emitOne (events.js:116:13)
at ClientRequest.emit (events.js:211:7)
at Socket.socketOnEnd (_http_client.js:423:9)
at emitNone (events.js:111:20)
at Socket.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
(node:19424) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:19424) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
4

0 回答 0