Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Order of HTTP POST parameters changed?

An HTTP POST request with content type "application/x-www-form-urlencoded" has parameters encoded in the body in the form of key=value pairs, concatenated with the & delimiter. Example from http://www.opencalais.com/HTTPexamples:

POST /enlighten/rest HTTP/1.1
Host: api.opencalais.com
Content-Type: application/x-www-form-urlencoded
Content-Length: length

licenseID=string&content=string&paramsXML=string

I take it when a user fills out an ordinary POST form on a web page, the browser is not bound to any particular order of the key=value pairs when submitting the request.

However, does the HTTP protocol say anything about this order as the request is passed on by intermediate servers? Do any servers such as Apache, nginx, IIS rearrange the parameters? If such a POST request is sent to a server can one expect that the back-end server code (say PHP, Perl, Java) has access to the identical HTTP request body as sent?

like image 693
Stephan Wehner Avatar asked Oct 27 '25 00:10

Stephan Wehner


1 Answers

Browsers are supposed to send application/x-www-form-urlencoded data in tree order. The spec doesn't make this very clear, but you can tease it out if you look carefully. See x-www-form-urlencoded-encoding-algorithm and Constructing the form data set. The decoding section also calls the output a "sorted list of name-value pairs".

So yes, a well-behaved proxy should preserve the order of form entries.

like image 175
Daniel Lubarov Avatar answered Oct 28 '25 19:10

Daniel Lubarov