【问题标题】:react native fetch and axios is not sending request on android emulatorreact native fetch 和 axios 没有在 android 模拟器上发送请求
【发布时间】:2021-03-14 21:57:38
【问题描述】:

我正在使用:

"react-native": "0.63.3",
"axios": "^0.21.0",
"react": "16.13.1",

这是一个简单的请求,看看发送请求是否成功:

  useEffect(() => {
    console.log('log here fast');
    axios
      .get('http://api.github.com/users/hacktivist123/repos')
      .then(function (response) {
        console.log('axios', response);
      })
      .catch(function (error) {
        console.log('axios error', error);
      });

    fetch('http://api.github.com/users/hacktivist123/repos')
      .then((response) => response.json())
      .then((data) => console.log(data));

    console.log('log here slow');
  }, []);

它甚至没有显示请求是否已发送。我在真实设备上运行了这个项目,它运行良好,我尝试了其他问题中给出的解决方案,但没有一个有效。

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
  package="com.tasks">

    <uses-permission android:name="android.permission.INTERNET" />

    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
      android:theme="@style/AppTheme"
      android:usesCleartextTraffic="true"
      tools:targetApi="28" 
      >

即使添加 network_security_config.xml 也没有帮助,也没有让构建项目出现一些错误。

【问题讨论】:

    标签: android react-native axios fetch


    【解决方案1】:

    显然这是一个 react-nativ 中的错误e,它是 open 在他们的 github issues 上,我试过了使用 android api 21 并正在发送请求,但未使用 api 29

    【讨论】:

      猜你喜欢
      • 2018-11-05
      • 2018-12-06
      • 2019-04-24
      • 1970-01-01
      • 2020-05-01
      • 2020-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多