【发布时间】:2018-06-11 20:25:23
【问题描述】:
我在 RN 中有以下代码:
postToServer(){
const requestBody = 'pin=1&status=false';
return fetch('https://192.168.10.200/writeStatus.php', {
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
body: requestBody
}).then((response) => response.json())
.then((responseJson) => {
console.log(responseJson);
});
}
我也有以下 php 文件:
<?php
header('Access-Control-Allow-Origin: *');
$data = json_decode(file_get_contents('php://input'), true);
print_r($data);
?>
当我运行 postToServer 时,我收到:
可能的未处理的 Promise Rejection (id: 0): TypeError: Network 请求失败类型错误:网络请求失败 在 XMLHttpRequest.xhr.onerror (http://192.168.10.248:19001/node_modules/expo/AppEntry.bundle?platform=android&dev=true&minify=false&hot=false&assetPlugin=P:\sandbox\MojDom1\node_modules\expo\tools\hashAssetFiles:7854:16) 在 XMLHttpRequest.dispatchEvent (http://192.168.10.248:19001/node_modules/expo/AppEntry.bundle?platform=android&dev=true&minify=false&hot=false&assetPlugin=P:\sandbox\MojDom1\node_modules\expo\tools\hashAssetFiles:12942:35) ...(这里剩下一些行 - 我对链接有限制) 在 MessageQueue.callFunctionReturnFlushedQueue (http://192.168.10.248:19001/node_modules/expo/AppEntry.bundle?platform=android&dev=true&minify=false&hot=false&assetPlugin=P:\sandbox\MojDom1\node_modules\expo\tools\hashAssetFiles:2122:12)
大家有什么建议吗?
【问题讨论】:
-
您在哪个操作系统(android 或 ios)中或在模拟器或真实设备中遇到此问题?
-
此调试器消息来自 Win10 上的 Chrome。我使用 exp 在我的 android 7.0 Huawei P10 上运行应用程序
标签: android reactjs react-native fetch typeerror