简体   繁体   中英

how to make my expo (react native) android emulator access C# .net backend api using localhost?

I am trying to build mobile app using react native and expo. When I try to access C# backend for fetching data, I have a "Network request failed" issue. The backend is built using C# .net core 3.0, and there is no authentication applied. For instance, one get request is for fetching all data from database: http://localhost:5000/ref-entity/load-all/0/1

the following are the experiments I have done:

  1. the url http://localhost:5000/ref-entity/load-all/0/1 is working in postman.
  2. but if I use http://10.0.2.2:5000/ref-entity/load-all/0/1 in expo android emulator, I will get a "Network request failed" error.
  3. I have figured out it is the c# backend issue, since if I build a simple backend using node.js, this url http://10.0.2.2:4000/test is absolutely working in the emulator.

I believe it must be the c# backend is blocking the access from android emulator (10.0.2.2), but nodejs is not. I still cannot figure out which configuration I should try.

每当我遇到网络请求失败等问题时,我都会在 android EMULATOR 上尝试这个及其对我的工作。

http://10.0.2.2:5000

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM