react-native android:可能未处理的承诺拒绝(id:0):TypeError:网络请求失败

时间:2021-07-16 10:40:27

标签: react-native-android

我正在尝试调用 fetch 请求并且它在 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

enter image description here

0 个答案:

没有答案