慕容的工作随笔

慕容的工作随笔

记录学习和工作

【转载】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;
    }

评论 (0)

还没有评论,来做第一个吧。

发表评论

提交后需管理员审核通过后显示