Home > Backend Development > PHP Tutorial > Why Doesn't POST Support `enctype='text/plain'` While GET Does?

Why Doesn't POST Support `enctype='text/plain'` While GET Does?

Linda Hamilton
Release: 2024-12-05 16:24:11
Original
400 people have browsed it

Why Doesn't POST Support `enctype=

Incompatibility of method="post" and enctype="text/plain"

When attempting to use the following form:

<form method="post" enctype="text/plain" action="proc.php">
Copy after login

you may encounter difficulties in successfully transmitting form data to the "proc.php" file. What causes this problem, and why is it impossible to utilize "text/plain" encoding with the "post" method while it is possible with the "get" method?

Explanation:

PHP's inability to handle "text/plain" encoding with the "post" method is the root of this issue (and it's not a bug):

https://bugs.php.net/bug.php?id=33741

For the "enctype" attribute in the "

" tag, the following valid values are:

  • application/x-www-form-urlencoded
  • multipart/form-data

The first value is the default, and the second is only required for file uploads.

Reason for PHP's behavior:

Alohci provided an explanation for why PHP does not populate the $_POST array and instead stores the value in the $HTTP_RAW_POST_DATA variable:

Distinction between GET and POST:

  • GET: Variables are included in the URL as query strings and must be URL-encoded. Even with "enctype=text/plain," browsers URL-encode variables.
  • POST: Variables are not part of the URL but are sent as the last header in HTTP requests (POSTDATA). You can specify whether to send them as "text/plain" or "application/x-www-form-urlencoded," but the latter is the only option that eliminates ambiguity.

The above is the detailed content of Why Doesn't POST Support `enctype='text/plain'` While GET Does?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template