What#39;s the difference between POST and raw POST in PHP at all?(PHP 中的 POST 和原始 POST 之间有什么区别?)
问题描述
阅读答案后我有这个问题 这里,有什么区别?
I have this question after reading the answer here, what's the difference at all?
是否可以使用 html 提交原始 POST ?
Is it possible to submit raw POST with html ?
推荐答案
我们可以将表单提交分为三种情况:
We can divide form submissions in three cases:
- 内容类型为 
application/x-www-form-urlencoded的提交 - 内容类型为 
multipart/form-data 的提交 - 其他提交.
 
在情况 1 和 3 中,$HTTP_RAW_POST_DATA 包含原始帖子数据(除非选项是 always_populate_raw_post_data 设置为 false,在这种情况 $HTTP_RAW_POST_DATA 在情况 1) 中为空,即数据与客户端(通常是浏览器)发送的数据完全相同.在第 1 种情况下,数据的形式如
In cases 1 and 3, $HTTP_RAW_POST_DATA contains the raw post data (except if the option is always_populate_raw_post_data is set to false, in which case $HTTP_RAW_POST_DATA is empty in case 1), i.e., the data exactly as the client (usually the browser) has sent it. In case, 1, the data has a form such as
key1=value1&key2=value2&key3[]=value3.1&key3[]=value3.2
PHP 自动解析这个,所以 $_POST 变成:
PHP automatically parses this, so that $_POST becomes:
$_POST = array(
    "key1" => "value1",
    "key2" => "value2",
    "key3" => array("value3.1", "value3.2");
)
原始数据的内容也可以通过php://input访问,即使在always_populate_raw_post_data设置为false的情况1>.尤其是,file_get_contents("php://input") 给出了 $HTTP_RAW_POST_DATA 已经或应该拥有的相同数据.
The contents of the raw data can also be access through php://input, even in case 1 when always_populate_raw_post_data is set to false. In particular, file_get_contents("php://input") gives the same data $HTTP_RAW_POST_DATA has or would have.
在情况 3 中,POST 数据是任意的,$_POST 将是一个空数组,并且 $HTTP_RAW_POST_DATA 将始终被填充.
In case 3, in which the POST data is arbitrary, $_POST will be an empty array and $HTTP_RAW_POST_DATA will always be populated.
案例 2 是一个特殊的案例.在这种情况下,PHP 将解析数据,$_POST 将获取不是上传文件的字段的内容,而是 php://input 和 $HTTP_RAW_POST_DATA 将不可用.
Case 2 is a special one. In that case, PHP will parse the data and $_POST will get the content of the fields which are not uploaded files, but php://input and $HTTP_RAW_POST_DATA will be unavailable.
这篇关于PHP 中的 POST 和原始 POST 之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP 中的 POST 和原始 POST 之间有什么区别?
				
        
 
            
        基础教程推荐
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
 - 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
 - php中的PDF导出 2022-01-01
 - 将变量从树枝传递给 js 2022-01-01
 - php 7.4 在写入变量中的 Twig 问题 2022-01-01
 - Web 服务器如何处理请求? 2021-01-01
 - php中的foreach复选框POST 2021-01-01
 - PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
 - 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
 - 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
				
				
				
				