3

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?

1
  • I don't see a reason for the intermediate servers to do that. Dec 29, 2012 at 20:16

1 Answer 1

5

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.