在使用xml-rpc的时候,server端获取client数据,主要是通过php输入流input,而不是$_post数组。所以,这里主要探讨php输入流php://input对一php://input介绍,php官方手册文档有一段话对它进行了很明确地概述。
“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”.
翻译过来,是这样:
“php://input可以读取没有处理过的POST数据。相较于$HTTP_RAW_POST_DATA而言,它给内存带来的压力较小,并且不需要特殊的php.ini设置。php://input不能用于enctype=multipart/form-data”
PHP 8.5.5 PHP 8.5.5 是 PHP 8.5 分支的维护更新版本。该版本延续了“小步快跑”的迭代逻辑,通过深度错误修复、底层性能微调以及安全加固,旨在为开发者提供一个更健壮、更高效的运行环境。该版本严格遵守语义化版本规范,不包含破坏性变更。
下载我们应该怎么去理解这段概述呢?!我把它划分为三部分,逐步去理解。
读取POST数据不能用于multipart/form-data类型php://input VS $HTTP_RAW_POST_DATA读取POST数据PHPer们一定很熟悉$_POST这个内置变量。$_POST与php://input存在哪些关联与区别呢?另外,客户端向服务端交互数据,最常用的方法除了POST之外,还有GET。既然php://input作为PHP输入流,它能读取GET数据吗?这二个问题正是我们这节需要探讨的主要内容。
经验告诉我们,从测试与观察中总结,会是一个很凑效的方法。这里,我写了几个脚本来帮助我们测试。
@file 192.168.0.6:/phpinput_server.php 打印出接收到的数据@file 192.168.0.8:/phpinput_post.php 模拟以POST方法提交表单数据@file 192.168.0.8:/phpinput_xmlrpc.php 模拟以POST方法发出xmlrpc请求.
@file 192.168.0.8:/phpinput_get.php 模拟以GET方法提交表单表数phpinput_server.php与phpinput_post.php立即学习“PHP免费学习笔记(深入)
”;
代码如下复制代码//@file phpinput_server.php$raw_post_data = file_get_contents('php://input', 'r');echo "-------$_POST------------------n";echo var_dump($_POST) . "n";echo "-------php://input-------------n";echo $raw_post_data . "n";?>//@file phpinput_post.php$http_entity_body = 'n=' . urldecode('perfgeeks') . '&p=' . urldecode('7788');$http_entity_type = 'application/x-www-form-urlencoded';$http_entity_length = strlen($http_entity_body);$host = '192.168.0.6';$port = 80;$path = '/phpinput_server.php';$fp = fsockopen($host, $port, $error_no, $error_desc, 30);if ($fp) {fputs($fp, "POST {$path} HTTP/1.1rn");fputs($fp, "Host: {$host}rn");fputs($fp, "Content-Type: {$http_entity_type}rn");fputs($fp, "Content-Length: {$http_entity_length}rn");fputs($fp, "Connection: closernrn");fputs($fp, $http_entity_body . "rnrn");while (!feof($fp)) {$d .= fgets($fp, 4096);}fclose($fp);echo $d;}?>我们可以通过使用工具ngrep抓取http请求包(因为我们需要探知的是php://input,所以我们这里只抓取http Request数据包)。我们来执行测试脚本phpinput_post.php代码如下复制代码@php /phpinput_post.phpHTTP/1.1 200 OKDate: Thu, 08 Apr 2010 03:23:36 GMTServer: Apache/2.2.3 (CentOS)X-Powered-By: PHP/5.1.6Content-Length: 160Connection: closeContent-Type: text/html; charset=UTF-8-------$_POST------------------array(2) {["n"]=> string(9) "perfgeeks"["p"]=> string(4) "7788"}-------php://input-------------n=perfgeeks&p=7788通过ngrep抓到的http请求包如下:T 192.168.0.8:57846 -> 192.168.0.6:80 [AP]POST /phpinput_server.php HTTP/1.1..
Host: 192.168.0.6..Content-Type: application/x-www-form-urlencoded..Co ntent-Length: 18..Connection: close....n=perfgeeks&p=7788....
仔细观察,我们不难发现1,$_POST数据,php://input 数据与httpd entity body数据是“一致”的2,http请求中的Content-Type是application/x-www-form-urlencoded ,它表示http请求body中的数据是使用http的post方法提交的表单数据,并且进行了urlencode()处理。
(注:注意加粗部分内容,下文不再提示).
1 2
