Heim >Backend-Entwicklung >PHP-Tutorial >PHP如何接收post传递的json数据

PHP如何接收post传递的json数据

PHPz
PHPzOriginal
2016-06-02 11:31:076436Durchsuche

PHP接收post传递的json数据的方法:可以使用【file_get_contents('php://input')】方法来接收。【php://input】是一个流,可以读取没有处理过的POST数据(即原始数据)。

PHP如何接收post传递的json数据

PHP如何接收post来的json数据?

要在PHP中整体接收POST数据,有两种方法。

注意,要使用以下两种方法,Content-Type不能为multipart/form-data。

方法一:

使用:file_get_contents('php://input')

其中,php://input是一个流,可以读取没有处理过的POST数据(即原始数据)。相较于$HTTP_RAW_POST_DATA而言,它给内存带来的压力较小,并且不需要特殊的php.ini设置。

方法二:

使用此方法,需要设置php.ini中的always_populate_raw_post_data值为On。

使用$HTTP_RAW_POST_DATA,包含了POST的原始数据。但这不是一个超全局变量,要在函数中使用它,必须声明为global,或使用$GLOBALS['HTTP_RAW_POST_DATA']代替。

更多相关知识,请访问 PHP中文网!!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn