简体   繁体   English

Axios React Native 网络错误 Android Expo

[英]Axios Network Error in React Native with Expo in Android

I'm trying to run an API call in React Native on Android with Expo using Axios, but I'm encountering a.network error.我正在尝试使用 Axios 在 Android 和 Expo 上的 React Native 中运行 API 调用,但我遇到了网络错误。 I tried some solutions, but nothing seems to work.我尝试了一些解决方案,但似乎没有任何效果。 This is the error displayed in the console:这是控制台中显示的错误:

Network Error
at node_modules\\axios\\lib\\core\\AxiosError.js:3:0in \<global\>
at node_modules\\axios\\lib\\adapters\\xhr.js:138:8 in handleAbort
at node_modules\\event-target-shim\\dist\\event-target-shim.js:818:20 in EventTarget.prototype.dispatchEvent
at node_modules\\react-native\\Libraries\\Network\\XMLHttpRequest.js:647:10 in setReadyState
at node_modules\\react-native\\Libraries\\Network\\XMLHttpRequest.js:396:6 in didCompleteResponse
at node_modules\\react-native\\Libraries\\vendor\\emitter_EventEmitter.js:150:10 in EventEmitter#emit
at node_modules\\react-native\\Libraries\\BatchedBridge\\MessageQueue.js:417:4 in callFunction
at node_modules\\react-native\\Libraries\\BatchedBridge\\MessageQueue.js:114:6 in guard$argument_0
at node_modules\\react-native\\Libraries\\BatchedBridge\\MessageQueue.js:368:10 in guard
at node_modules\\react-native\\Libraries\\BatchedBridge\\MessageQueue.js:113:4 in callFunctionReturnFlushedQueue

I tried changing the localhost in the API link to my IP address, as well as to 10.0.2.2, but nothing worked.我尝试将 API 链接中的本地主机更改为我的 IP 地址以及 10.0.2.2,但没有任何效果。 I checked my inte.net permission in AndroidManifest and made some other permission changes to the file, but nothing seemed to resolve it.我在 AndroidManifest 中检查了我的 inte.net 权限并对文件进行了一些其他权限更改,但似乎没有任何解决办法。 I hope to find a solution to the problem soon.我希望尽快找到解决问题的办法。

if you are using a tool like expo go, [ axiosError: Network error ] is simply an error saying that the api you provided may not be reached.如果您使用的是 expo go 之类的工具,[ axiosError: Network error ] 只是一个错误,表示您提供的 api 可能无法访问。 so if you want to pull data from a local storage instead of cloud storage... you may create a server like for example php artisan serve then create an Ngrok server for that server, afterwards take the link you received from the ngrok then use it as your new API endpoint所以如果你想从本地存储而不是云存储中提取数据......你可以创建一个服务器,例如php artisan serve然后为该服务器创建一个 Ngrok 服务器,然后获取你从 ngrok 收到的链接然后使用它作为您的新 API 端点

im the same problem.我有同样的问题。 you found solution l你找到了解决方案 l

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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