首页 > 解决方案 > react-native android:可能的未处理承诺拒绝(id:0):TypeError:网络请求失败

问题描述

我正在尝试调用 fetch request 并且它在 Ios 中运行良好但是当我在我的 android 设备中运行时出现错误

let CONVERT_FILE = "https://myUrl/convertFile";
const response = await fetch(CONVERT_FILE, {
  method: "POST",
  headers: utils.getApplicationHeaders(token),
  body:res
})
console.log("response",response)

const json = await response.json();
console.log("JSON",json)
return json;

我也尝试添加 AndroidManifest.xml

 android:usesCleartextTraffic="true"
 android:networkSecurityConfig="@xml/network_security_config"

在 network_security_config.xml

  <?xml version="1.0" encoding="utf-8"?>
     <network-security-config>
        <base-config cleartextTrafficPermitted="true"/>
     </network-security-config>

错误是

Possible Unhandled Promise Rejection (id: 0): TypeError: Network request failed

在此处输入图像描述

标签: react-native-android

解决方案


推荐阅读