简体   繁体   English

Android:[AxiosError:网络错误] Expo React Native

[英]Android: [AxiosError: Network Error] Expo React Native

Relevant modules used:使用的相关模块:

  • "expo": "~46.0.9" “世博会”:“~46.0.9”
  • "axios": "^0.27.2" “axios”:“^0.27.2”

I'm trying to fetch some data, everything works just fine on iOS devices but the problem comes when using an Android, the network fails for some reason:我正在尝试获取一些数据,在 iOS 设备上一切正常,但使用 Android 时出现问题,网络由于某种原因出现故障:

Android Running app on sdk_gphone64_arm64
[AxiosError: Network Error]

Here's the line of code that causes it:这是导致它的代码行:

const { data } = await axios.get('http:<my IP or 'localhost'>:<port>/endpoint');

Any ideas on how to fix it?关于如何解决它的任何想法?

在此处输入图像描述

The solution for this was that Axios didn't really need my real IP address.对此的解决方案是 Axios 并不真正需要我真正的 IP 地址。 It needed the IP that expo gives you when you start the metro bundler.它需要 expo 在您启动 Metro 捆绑器时为您提供的 IP。

So instead of:所以而不是:

axios.get('http:<my IP or 'localhost'>:<port>/endpoint')

I changed it for:我将其更改为:

axios.get('http:192.168.100.20:<port>/endpoint')

Now it is working.现在它正在工作。

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

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