【发布时间】:2018-04-22 23:14:23
【问题描述】:
我在 React Native 工作,我使用 PHP 作为后端,当我使用 fetch POST 请求时,我得到了很奇怪的错误,我不知道为什么会这样。我检查了网址,所以它没有问题,正常的fetch() 在没有POST 的情况下也可以正常工作,但是当我尝试发布它时会发生。当我在本地服务器中尝试获取 POST 时,它可以工作.. 但在服务器中,我收到此错误:
错误:com.facebook.react.bridge.ReadableNativeMap 无法转换为 java.lang.String
反应原生代码:
fetch('http://xxx/react_test1', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: inputName,
email: inputEmail,
phone: inputPhone
}),
}).then((response) => response.json())
.then((responseJson) => {
Alert.alert(responseJson);
}).catch((error) => {
alert(error);
});
【问题讨论】:
-
这个请求对我来说确实不错。您可以通过检查有效负载正文并查看值是否有效来进行调试吗?
-
我猜答案是 Alert.alert('string', responseJson),试试这样,因为 Alert.alert 需要 2 个值。
标签: react-native fetch