【问题标题】:axios didn't work with react native Error networkaxios 不适用于反应原生错误网络
【发布时间】:2021-10-20 08:19:51
【问题描述】:

我遇到了axiosreact native 的问题,我不知道是什么问题。

axios.catch 方法是发送错误内容的:Network Error

这里是 /Android/app/src/main/AndroidManifest.xml 的内容:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.eruditio">

    <uses-permission android:name="android.permission.INTERNET" />
    
    <application
      android:networkSecurityConfig="@xml/network_security_config"
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
      android:usesCleartextTraffic="true"
      android:theme="@style/AppTheme">
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
      <activity
      android:name="com.zoontek.rnbootsplash.RNBootSplashActivity"
      android:theme="@style/BootTheme"
      android:launchMode="singleTask">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    </application>
</manifest>

/Android/app/src/main/res/xml/network_security_config.xml的内容(是SSL域):

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
        </trust-anchors>
    </base-config>
</network-security-config>

感谢您对我的问题感兴趣,希望您能找出问题所在。

【问题讨论】:

    标签: android react-native axios


    【解决方案1】:

    这可能与自 axios 0.19.0 以来的已知问题有关,在这种情况下将 axios 降级到 ^0.18.0 对我有帮助,但 here you can find 更多信息和建议。 还有可能重复的问题。

    【讨论】:

    • 感谢您的帮助,我已经使用“axios”:“^0.21.1”,但仍然无法正常工作,但它适用于本地服务器和其他服务器,仅在此服务器上我认为它是一个安全问题,因为我没有找到关于我在 /var/log/apache2/access.log 上提出的请求的任何日志或 /var/log/apache2/error.log 上的任何错误
    • 如果您使用 Flipper 工具,请尝试禁用它并再次检查
    猜你喜欢
    • 2023-03-08
    • 2018-02-09
    • 1970-01-01
    • 2021-04-16
    • 2018-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-16
    相关资源
    最近更新 更多