共计 316 个字符,预计需要花费 1 分钟才能阅读完成。
普通情况下,application/json类型的数据无法直接使用$_POST或者$_REQUEST获取到,需要用到file_get_contents('php://input'),所以在此封装了一个方法,方便读取
function getPostData()
{
if (empty($_POST) && false !== strpos($_SERVER["CONTENT_TYPE"], 'application/json')) {
$content = file_get_contents('php://input');
$post = json_decode($content, true);
} else {
$post = $_POST;
}
return $post;
}
正文完