最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - node-fetch connect ETIMEDOUT error - Stack Overflow

programmeradmin0浏览0评论

I am trying to get 200 status code in response, but as a result it's ETIMEDOUT. I can't understand, how is it possible that I can grab successful response via postman, but same via node-fetch responding with ETIMEDOUT always. Here is an example of code:

const Resource = {
  get: cb => {
    fetch('', {
      method: 'POST',
      headers: {'Content-Type': 'application/x-www-form-urlencoded'},
      body: {...some body...},
    }).then(res => {
      if (res.status !== 200) cb(`Status: ${res.status}, ${res.statusText}`)
      return res.text()
    }).then(data => {
        cb(null, data)
      }).catch((err) => {
       console.log('ERROR: ', err)
      })
  }
}

and here is response:

ERROR: { FetchError: request to failed, reason: connect ETIMEDOUT at ClientRequest.<anonymous> (C:\Users\projects\DSSRQ\node_modules\node-fetch\lib\index.js:1393:11) at emitOne (events.js:116:13) at ClientRequest.emit (events.js:211:7) at TLSSocket.socketErrorListener (_http_client.js:387:9) at emitOne (events.js:116:13) at TLSSocket.emit (events.js:211:7) at emitErrorNT (internal/streams/destroy.js:64:8) at _binedTickCallback (internal/process/next_tick.js:138:11) at process._tickCallback (internal/process/next_tick.js:180:9) message: 'request to failed, reason: connect ETIMEDOUT', type: 'system', errno: 'ETIMEDOUT', code: 'ETIMEDOUT' }

I am trying to get 200 status code in response, but as a result it's ETIMEDOUT. I can't understand, how is it possible that I can grab successful response via postman, but same via node-fetch responding with ETIMEDOUT always. Here is an example of code:

const Resource = {
  get: cb => {
    fetch('https://example.', {
      method: 'POST',
      headers: {'Content-Type': 'application/x-www-form-urlencoded'},
      body: {...some body...},
    }).then(res => {
      if (res.status !== 200) cb(`Status: ${res.status}, ${res.statusText}`)
      return res.text()
    }).then(data => {
        cb(null, data)
      }).catch((err) => {
       console.log('ERROR: ', err)
      })
  }
}

and here is response:

ERROR: { FetchError: request to https://example. failed, reason: connect ETIMEDOUT at ClientRequest.<anonymous> (C:\Users\projects\DSSRQ\node_modules\node-fetch\lib\index.js:1393:11) at emitOne (events.js:116:13) at ClientRequest.emit (events.js:211:7) at TLSSocket.socketErrorListener (_http_client.js:387:9) at emitOne (events.js:116:13) at TLSSocket.emit (events.js:211:7) at emitErrorNT (internal/streams/destroy.js:64:8) at _binedTickCallback (internal/process/next_tick.js:138:11) at process._tickCallback (internal/process/next_tick.js:180:9) message: 'request to https://example. failed, reason: connect ETIMEDOUT', type: 'system', errno: 'ETIMEDOUT', code: 'ETIMEDOUT' }

Share Improve this question asked Jul 25, 2018 at 16:07 blindeveloperblindeveloper 1211 gold badge1 silver badge5 bronze badges 6
  • Are you actually having http or https as protocol? – The Oracle Commented Jul 25, 2018 at 16:49
  • this one is covered by https – blindeveloper Commented Jul 25, 2018 at 17:29
  • your target host is using what protocol? http or https? – The Oracle Commented Jul 25, 2018 at 17:32
  • my target host is using https protocol – blindeveloper Commented Jul 26, 2018 at 8:33
  • I am doing in on my local nodejs environment. I've tried using cross-fetch lib (npmjs./package/cross-fetch) with default example of fetching data and got the same error. – blindeveloper Commented Jul 26, 2018 at 9:55
 |  Show 1 more ment

1 Answer 1

Reset to default 4

It looks like it was because of the proxy limitation.

发布评论

评论列表(0)

  1. 暂无评论