方法= QUOT;交" ENCTYPE = QUOT; text / plain的"不兼容? [英] method="post" enctype="text/plain" are not compatible?
问题描述
< form method =postenctype =text / plainaction =proc。 PHP>
表单数据无法正确发送到proc.php文件。为什么?问题是什么?为什么我不能在post中使用text / plain编码,但是我可以在get方法中使用它?
[修正]
答案是,因为PHP无法处理它(并且它不是bug):
https://bugs.php.net/bug.php?id = 33741
$ b $
enctype的有效值在< form>标签是:
application / x-www-form-urlencoded
multipart / form-data
第一个是默认设置,第二个只有在您上传文件时才需要。
@Alohci 提供解释为什么PHP不会填充 $ _ POST
数组,但将值存储在变量 $ HTTP_RAW_POST_DATA
中。
$ text / plain
enctype:
file1.php:
< form method =postenctype =text / plainaction =file2.php>
< textarea name =input1> abc
input2 = def< / textarea>
< input name =input2value =ghi/>
< input type =submit>
< / form>
file2.php:
<?php
print($ HTTP_RAW_POST_DATA);
?>
结果:
input1 = abc
input2 = def
input2 = ghi
无法区分 input1
和 input2
变量的值。它可以是
abc \r\\\
, input2 =
input2 = def ghi
,以及
abc
,input2 = def\r\\\
input2 = ghi
使用时无此问题前面提到的另外两种编码。
GET和POST的区别:
enctype = text / plain
- 它只是被浏览器忽略;你可以使用Wireshark测试它来嗅探请求数据包),发送POST时,
text / plain
还是 application / x-www-form-urlencoded
,但第二个是唯一的非模糊解决方案
When I use
<form method="post" enctype="text/plain" action="proc.php">
form data can not be sent to proc.php file properly. Why? What is the problem? Why I can't use text/plain encoding with post but I can use it with get method?
[Revised]
The answer is, because PHP doesn't handle it (and it is not a bug):
https://bugs.php.net/bug.php?id=33741
Valid values for enctype in <form> tag are:
application/x-www-form-urlencoded
multipart/form-data
The first is the default, the second one you need only when you upload files.
@Alohci provided explanation why PHP doesn't populate $_POST
array, but store the value inside a variable $HTTP_RAW_POST_DATA
.
Example of what can go wrong with text/plain
enctype:
file1.php:
<form method="post" enctype="text/plain" action="file2.php">
<textarea name="input1">abc
input2=def</textarea>
<input name="input2" value="ghi" />
<input type="submit">
</form>
file2.php:
<?php
print($HTTP_RAW_POST_DATA);
?>
Result:
input1=abc
input2=def
input2=ghi
No way to distinguish what is the value of input1
and input2
variables. It can be
- input1=
abc\r\ninput2=def
, input2=ghi
, as well as - input1=
abc
, input2=def\r\ninput2=ghi
No such problem when using the other two encodings mentioned before.
The difference between GET and POST:
- in GET, the variables are part of URL and are present in URL as query string, therefore they must be URL-encoded (and they are, even if you write
enctype="text/plain"
- it just gets ignored by the browser; you can test it using Wireshark to sniff the request packets), - when sending POST, the variables are not part of URL, but are sent as the last header in HTTP request (POSTDATA), and you can choose whether you want to send them as
text/plain
orapplication/x-www-form-urlencoded
, but the second one is the only non-ambiguous solution.
这篇关于方法= QUOT;交" ENCTYPE = QUOT; text / plain的"不兼容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!