客户端请求php,发送的请求头Content-Type为JSON,PHP接收不到$_POST数据

客户端请求php,发送的请求头Content-Type为”Content-Type”: ‘application/json;charset=utf-8’ ,PHP接收不到$_POST数据。原因是PHP只默认转码这两个请求头
application/x-www-form-urlencoded
text/html;
而想要接收,则通过下面的方法可以转换

$put=file_get_contents('php://input');
$put=json_decode($put,1);
foreach ($put as $key => $value) {
    $_POST[$key]=$value;   
}

Related posts:

Leave a Reply

Your email address will not be published.