我遇到了以下错误.

fetch("https://XXreachable-domainXX.de/api/test", {
            method: "post",

            body: JSON.stringify({
                param: 'param',
                param1: 'param',

            })
        }
    )
        .then((response) = > response.json()
    )
    .
    then((responseData) = > {
        ToastAndroid.show(
        "Response Body -> " + JSON.stringify(responseData.message), ToastAndroid.SHORT
    )
})
    .
    catch((error) = > {
        console.warn(error);
})
    ;

应用程序现在抛出一个错误:

类型错误:网络请求失败

当我将代码更改为GET请求时,它可以在带有窗口的浏览器中正常工作.alert()作为返回,它很酷,而且chrome扩展postman 也能正确返回数据.

推荐答案

这个React Native的错误是相当无用的,所以您需要首先获得实际的底层错误.最简单的方法是编写一个小型本机程序,只需使用HttpsURLConnection执行相同的查询.

对我来说,实际误差是java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

考虑到浏览器和postman 对请求没有任何问题,这很可能也是您的情况.要判断它,请运行openssl s_client -connect XXreachable-domainXX.de:443 -showcerts.如果存在证书错误,请先修复它们,这样可以节省编写本机程序的时间.

编辑:实际上,查看react native所有底层android错误的最简单方法就是在终端中运行"adb logcat"

React-native相关问答推荐

'无法解析模块.安装react-native-pager-view后的实用程序/平台

try 使用JWT-DECODE解码令牌时出错

单击react 本机时如何从同一屏幕更改内容

到达安装依赖项时 EAS 构建错误

React Native Axios 通过数组的键过滤

如何在 react-native 中刷新 Flatlist 数据?

TextInput 防止 ScrollView 滚动

ReactJS toLowerCase 不是一个函数

如何通过 node ID 获取真实元素?

在 React Native 中计算两个 lat+lng 坐标之间的距离?

如何解决react-navigation 问题:Animated: `useNativeDriver` is not supported because the native animated module is missing.?

react-native 自动完成文本输入

SyntaxError:Strict mode does not allow function declarations in a lexically nested statement on a newly created app

更新 this.state.dataSource 不会更新 ListView

如何使用 Expo 在真实的 iOS 设备上运行应用程序?

iOS ActionSheet 的 Android 类似功能

React Native Android 负边距(Margins)

在react-native中调试应用程序崩溃

zoom 到指定的标记 react-native-maps

将 Picker 绑定到 React Native 中的 Picker.Item 列表