views:

159

answers:

2

The HTTP spec says that a POST request can contain an arbitrary body of data.

An HTML form element can POST to a URL and may contain input elements, but those input elements get turned into a query string.

How can I get a form to also send along data in the body of the HTTP POST request that it sends when its submit button is pressed?

Edit: While this question is quite happily independent of any other question, it is related to http://stackoverflow.com/questions/2925796/post-xml-to-server-receive-pdf

Somehow, I want to be able to send data in a POST's body, and I want the browser to automagically handle the HTTP response (which will be an application/pdf). This question is phrased in such a way that I am hoping I can avoid using XmlHttpRequest (AJAX) and just use the browser's built-in behaviour with form elements to properly submit data and handle the PDF that is sent back.

A: 

Have you specified method="post" in your form element? It sounds like you're sending a get request.

k_b
+1  A: 

Use javascript to send an ajax request when the button is pressed and cancel the form submission. Form submits will always be name/value pairs. XForms can send customized data but if this is for public use it'll be years before XForms is supported by the majority of browsers in use, if ever.

Sam
If I use AJAX to do the POST, then the browser will not automagically handle the HTTP response, and I want it to. In other words, I am looking for an answer to the question that doesn't rely on JavaScript, but just HTML.
Shaggy Frog