React Native Http 请求在 Android 中不起作用

mar*_*vzc 5 react-native

使用FetchAxios处理对服务器的请求,在 Android 模拟器/设备上运行它时,它显示以下错误:

在此输入图像描述

这是请求代码:

fetch(URL,{
      method: 'POST',
      headers: {
        Accept: 'application/json',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
                email: userEmail,
                password: userPassword
            }),

        })
        .then((response) => response.json())
         .then((responseJson)=>{
             Alert.alert("bien");
       console.warn(responseJson);
             })
         .catch((error)=>{
         console.error(error);
     console.warn(error);
   });
Run Code Online (Sandbox Code Playgroud)

小智 16

由于 Http 请求在最新的 Android 更新中不起作用,我认为在 28 号到来之后。因此,您必须将以下属性添加到 AndroidManifest.xml

    <manifest 
        xmlns:tools="http://schemas.android.com/tools">

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

        <application
           android:usesCleartextTraffic="true"> 

                // ----------------

        </application>
   </manifest>
Run Code Online (Sandbox Code Playgroud)


mar*_*vzc 2

问题出在 URL 的 SSL 证书上