When any POST request is made, then you have to encode the data that forms the body of the request in some way.The HTML forms give us three methods of encoding which are:-
I was working on adding application/json, but that has been discontinued, however, other encodings are possible with HTTP requests which are generated using other means than an HTML form submission. The JSON is a common format for use with web services and some still use the SOAP version. The specifics of the formats don't matter to most developers. The main disclaimers are:
Once you are writing client-side code:
-
use multipart/form-data when your form includes any <input type="file"> elements
-
you can also use multipart/form-data or application/x-www-form-urlencoded but application/x-www-form-urlencoded will be more efficient
When you are writing server-side code:
Most of them for example Perl's CGI->param or the one exposed by PHP's
$_POST superglobal will take care of the differences for you. Don't bother trying to parse the raw input received by the server.
If you are debugging a library for parsing or generating the raw data, then you need to start worrying about the format. You might also want to know about it for interest's sake.
application/x-www-form-urlencoded is more or less the same as a query string on the end of the URL.
multipart/form-data is significantly more complicated but it allows entire files to be included in the data.