Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

How are parameters sent in an HTTP POST request?

In an HTTP GET request, parameters are sent as a query string:
 example.com/page?parameter=value&also=another
*

In an HTTP POST request, the parameters are not sent along with the URI.

Where are the values? In the request header? In the request body? What does it look like?
by

3 Answers

akshay1995
The values are sent in the request body, in the format that the content type specifies.

Usually the content type is application/x-www-form-urlencoded, so the request body uses the same format as the query string:

parameter=value&also=another
When you use a file upload in the form, you use the multipart/form-data encoding instead, which has a different format. It's more complicated, but you usually don't need to care what it looks like, so I won't show an example, but it can be good to know that it exists.
RoliMishra
The content is put after the HTTP headers. The format of an HTTP POST is to have the HTTP headers, followed by a blank line, followed by the request body. The POST variables are stored as key-value pairs in the body.

You can see this in the raw content of an HTTP Post, shown below:

POST /path/script.cgi HTTP/1.0
From: xyz@abc.com
User-Agent: HTTPTool/1.0
Content-Type: application/x-www-form-urlencoded
Content-Length: 32

home=Cosby&favorite+flavor=flies
kshitijrana14
The default media type in a POST request is application/x-www-form-urlencoded. This is a format for encoding key-value pairs. The keys can be duplicate. Each key-value pair is separated by an & character, and each key is separated from its value by an = character.
For example:
Name: John Smith
Grade: 19

Is encoded as:
Name=John+Smith&Grade=19

This is placed in the request body after the HTTP headers.

Login / Signup to Answer the Question.