当我使用post和put方法时,file_get_contents('php:// input')为空。我的put结尾的一个例子看起来像这样:/ v2 / table?tablecolumn = 7&anothertablecolumn = 4
所有方法现在都通过Postman发送。
以下是快速查看的简化版本:
if (($this->method === 'POST') || ($this->method === 'PUT')) {
$json = file_get_contents('php://input');
if(empty($json)) {
$this->rc = 211;
return;
}
}
发布于 2018-07-18 14:58:34
看起来你正在尝试以JSON格式发送和接收数据。总是更好地使用、尝试、捕捉和进行解析。
希望能帮上忙。
if(strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') != 0){
echo ('Request method must be POST!');
throw new Exception('Request method must be POST!');
}
$contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : '';
if(strcasecmp($contentType, 'application/json') != 0){
echo ('Content type must be: application/json');
throw new Exception('Content type must be: application/json');
}
try{
$Obj = json_decode(file_get_contents('php://input'), true);
}catch(Exception $e){
echo json_encode('{"result":"FALSE","message":"Caught exception: '.
$e->getMessage().' ~"}');
}
https://stackoverflow.com/questions/-100005594
复制相似问题