
遇到这么个情况,请大神指教 这个接口 https://api.testnet.huobi.pro/v1/common/symbols 在浏览器上可以正常访问返回数据:
但是使用 axios 请求却会报错:
报错信息: C:\Users\Maxzel\Desktop\huobi>node app.js (node:7804) UnhandledPromiseRejectionWarning: Error: connect ETIMEDOUT 174.37.154.236:80 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16) (node:7804) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejectiOns=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2) (node:7804) [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.
之后尝试改 headers,将 axios 换成 request,superagent 来请求都无法得到返回数据,但为什么浏览器又可以直接返回呢?应该怎么解决?
1 xqin 2020-06-01 21:25:58 +08:00 你发的那个 URL 应该是需要 FQ 的, 你的浏览器估计有开启代理, 所以你浏览器可以打开. 但你用 axios 请求时没有设置代理, 所以请求不到. |
5 ochatokori 2020-06-02 02:03:16 +08:00 via Android 你浏览器写的是 https,node 里面写的是 http |
6 BlackHole1 PRO 试了下在我这没有问题,考虑在后面添加歌 catch,看下具体的错误原因吧。感觉是网络问题导致的。虽然你写的 http,但是会自动跳转到 https,所以应该和这个没关系。还不行的话,列举下你的环境信息(node/axios veriosn) |
7 JayLin1011 2020-06-02 20:33:29 +08:00 `Promise` 的缺点之一就是内部跑出异常需要外部主动捕获。 |