React Native通过Fetch进行的POST请求抛出了网络请求失败
- 论坛
- React Native通过Fetch进行的POST请求抛出了网络请求失败
10 浏览
React Native通过Fetch进行的POST请求抛出了网络请求失败
我遇到了以下错误。
目前我正在使用React Native开发一个Android应用程序,因此我计划使用fetch来进行我的POST请求。
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); });
该应用现在抛出一个错误:
TypeError: 网络请求失败
当我将代码更改为GET请求时,它正常工作,在浏览器中使用window.alert()作为返回时也很好,Chrome扩展程序Postman也正确返回数据。