Axios request getting network error on Expo

淺唱寂寞╮ 提交于 2021-01-29 05:40:13

问题


I have an expo mobile application running on an Android emulator and I'm trying to make a request to a local Node.js API. The request is through HTTPS protocol so I created self-signed certificates to be able to try the application.

Every time I try to make a request to the API Axios throws a Network error.

Network Error

Stack trace:
  http://192.168.1.35:19001/node_modules%5Cexpo%5CAppEntry.bundle?platform=ios&dev=true&hot=false&minify=false:168381:25 in createError
  http://192.168.1.35:19001/node_modules%5Cexpo%5CAppEntry.bundle?  platform=ios&dev=true&hot=false&minify=false:168285:26 in handleError
  node_modules\event-target-shim\dist\event-target-shim.js:818:20 in EventTarget.prototype.dispatchEvent
  node_modules\react-native\Libraries\Network\XMLHttpRequest.js:600:10 in setReadyState
  node_modules\react-native\Libraries\Network\XMLHttpRequest.js:395:6 in __didCompleteResponse
  node_modules\react-native\Libraries\vendor\emitter\EventEmitter.js:189:10 in emit
  node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:416:4 in __callFunction
  node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:109:6 in __guard$argument_0
  node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard
  node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:108:4 in 
  callFunctionReturnFlushedQueue
  [native code]:null in callFunctionReturnFlushedQueue
  ...

I tried the following:

  • Configuring the API IP on the mobile application as 10.0.2.2 as suggested in the GitHub issue and didn't work.
  • Testing the application without HTTPS, which works perfectly fine.
  • Testing my application on an iOS device, but it has the same behaviour as the Android emulator, it works with HTTP but it does not with HTTPS.
  • Accessing the HTTPS URL from the emulator's browser, which also works.

My HTTPS server is configured as follows:

const httpsServer = https.createServer(Certificate.getCertificate(), app);
httpsServer.listen(Environment.PORT, "0.0.0.0");
Logger.logInfo(`Listening on port ${Environment.PORT} under HTTPS protocol.`);

In order to create the self-signed certificates, I followed the Heroku guide

来源:https://stackoverflow.com/questions/65512495/axios-request-getting-network-error-on-expo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!