admin管理员组文章数量:1333636
I cannot fetch anything from my local .NET webAPI (that's running on my computer) while using my react native app (Expo Go) that is "streamed" to my phone. The error I get is: TypeError: Network request failed
I am able to fetch other public test API's like "; with my app.
The backend is also reachable via Postman and browser by every device in the network, when trying to get response from it.
This is my setup:
- Computer that has the backend (192.168.8.100:7036) web API running AND the Expo Go (192.168.8.100:8081) server running.
- Phone that displays the app while being connected to the Expo Go server via Expo Go app.
- Every device is in the same network.
I cannot fetch anything from my local .NET webAPI (that's running on my computer) while using my react native app (Expo Go) that is "streamed" to my phone. The error I get is: TypeError: Network request failed
I am able to fetch other public test API's like "https://jsonplaceholder.typicode/todos/1" with my app.
The backend is also reachable via Postman and browser by every device in the network, when trying to get response from it.
This is my setup:
- Computer that has the backend (192.168.8.100:7036) web API running AND the Expo Go (192.168.8.100:8081) server running.
- Phone that displays the app while being connected to the Expo Go server via Expo Go app.
- Every device is in the same network.
3 Answers
Reset to default 0Your react native app cannot connect to your local server just like a web app or your postman app. To connect to your local server, use http://10.0.2.2:7036
instead of http://192.168.8.100:7036
for your API connection url.
Figured a workaround. Not sure 100% but the issue could've been caused by having my mobile app running localy trying to reach an api call on the same local server (just like engr.ukairo suggested earlier). Even calling directly by ip didn't work.
I decided to try ngrok and it works. Worth it and doesn't take alot of time to configure.
We had a similar issue. My colleague explained that by default, Android/Expo Go does not allow API calls over HTTP. That's why it functions as you said by using ngrok. I think, you still can use HTTP but you need to configure manually it in xml file about restriction.
本文标签: React Native (with Expo) fetch() TypeError Network request failed on same computerStack Overflow
版权声明:本文标题:React Native (with Expo) fetch() TypeError: Network request failed on same computer - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742357112a2459635.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论