[修订]
答案是,因为PHP无法处理它(并且它不是bug):
https://bugs.php.net/bug.php?id=33741
Valid values for enctype in <form> tag are:application/x-www-form-urlenpredmultipart/form-data
第一个是默认值,第二个仅在上载文件时才需要。
@Alohci 提供了解释,为什么PHP不填充
$_POST数组,而是将值存储在变量中
$HTTP_RAW_POST_DATA。
text/plainenctype 可能会出错的示例:
file1.php:
<form method="post" enctype="text/plain" action="file2.php"><textarea name="input1">abcinput2=def</textarea><input name="input2" value="ghi" /><input type="submit"></form>
file2.php:
<?phpprint($HTTP_RAW_POST_DATA);?>
结果:
input1=abcinput2=definput2=ghi
无法区分
input1和
input2变量的值是什么。有可能
- input1 =
abcrninput2=def
,input2 =ghi
以及 - input1 =
abc
,input2 =defrninput2=ghi
使用前面提到的其他两种编码时,没有这种问题。
GET和POST之间的区别:
- 在GET中,变量是URL的一部分,并以查询字符串的形式出现在URL中,因此 必须 对它们进行URL编码(即使您编写了这些变量
enctype="text/plain"
,浏览器也会忽略它;您可以使用Wireshark对其进行测试嗅探请求数据包), - 发送POST时,变量不是URL的一部分,而是作为HTTP请求(POSTDATA)中的最后一个标头发送的,您可以选择是否以
text/plain
或形式发送它们application/x-www-form-urlenpred
,但是第二个是唯一的明确解决方案。



