我无法使用PHP读取POST HTTP请求的正文! [英] I can't read my POST HTTP request's body with PHP !

查看:95
本文介绍了我无法使用PHP读取POST HTTP请求的正文!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从未使用过PHP,但是现在,我需要编写一个PHP文件,该文件在日志文件中显示POST HTTP请求的正文内容.

I've never used PHP but right now, I need to write a PHP file that displays in a log file the content of the body of a POST HTTP request.

我读到您可以通过_POST数组访问主体的变量. 不幸的是,它似乎是空的,尽管我很确定HTTP请求的主体中有东西!

I've read that you can access variables of the body via the _POST array. Unfortunately, it seems to be empty, although I'm pretty sure there is stuff in my HTTP request's body !

我应该使用什么来100%确定HTTP正文的内容?

What should I use to be 100% sure of the content of my HTTP body ?

谢谢.

推荐答案

$post_body = file_get_contents('php://input');

php://input允许您读取原始POST数据.它是$HTTP_RAW_POST_DATA占用较少内存的替代方法,不需要任何特殊的php.ini指令. php://input不适用于enctype ="multipart/form-data".

php://input allows you to read raw POST data. It is a less memory intensive alternative to $HTTP_RAW_POST_DATA and does not need any special php.ini directives. php://input is not available with enctype="multipart/form-data".

(来源: http://php.net/wrappers.php )

这篇关于我无法使用PHP读取POST HTTP请求的正文!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆