【转载】PHP接收json格式的POST数据

转自:https://blog.csdn.net/weixin_39983993/article/details/115504823

/**
* 获取 post 参数; 在 content_type 为 application/json 时,自动解析 json
* @return array
*/
private function initPostData()
{
if (empty($_POST) && false !== strpos($this->contentType(), 'application/json')) {
$content = file_get_contents('php://input');
$post = (array)json_decode($content, true);
} else {
$post = $_POST;
}
return $post;
}

点赞

发表回复

电子邮件地址不会被公开。必填项已用 * 标注