【发布时间】:2020-08-08 18:45:39
【问题描述】:
fetch("http://10.0.2.2:80/NewAdmin/scripts/main/transactions", {
method:'post',
headers:{
"Accept":"application/json",
"Content-type":"application/json"
},
// (var) payload looks like this {Header: "Sending", . . .}
body:JSON.stringify(payload)
})
.then(res => res.json())
.then(resp => console.log(resp))
.catch(err => console.log(err));
我的 PHP 代码
<?php
$json = json_decode(file_get_contents('php://input'), true);
echo $json;
if($json["Header"] == "Sending"){
echo json_encode('!WTF');
}else{
echo json_encode('WTF!');
}
?>
它返回“WTF!”——不是双关语。我错过了什么?
【问题讨论】:
-
做一些基本的调试。记录
file_get_contents('php://input')的值。记录$Jjson的值。 -
你是什么意思?
-
它返回 null
标签: javascript php react-native fetch