2

I can use a GET request to submit HTML form data. If a HEAD request is functionally identical to a GET, excluding content in the response, then should I be able to submit HTML form data with a HEAD?

The first line of the HTTP request might look something like this:

HEAD /processdata.php?first=john&last=doe&email=john@doe.com HTTP/1.1

RFC 2616 says:

The HEAD method is identical to GET except that the server MUST NOT return a 
message-body in the response.

(Almost a dupe of this question, except that I want to know if I can submit HTML form data.)

Responses based upon the spec appreciated. TIA.

Community
  • 1
  • 1
james.garriss
  • 12,959
  • 7
  • 83
  • 96

4 Answers4

2

HEAD is the same as GET except for the response not carrying the payload.

So yes, you can send whatever you would send with GET.

Julian Reschke
  • 40,156
  • 8
  • 95
  • 98
  • And we would expect that form data (in the query string) to be used to retrieve data from a server (though the data won't be included in the response because it's a HEAD) but not to save data on a server. Right? – james.garriss Nov 15 '11 at 19:05
  • Again, it's the same as GET, except for the response body. If GET saves something -- which of course is BAD BAD BAD -- then HEAD should, too. – Julian Reschke Nov 15 '11 at 19:14
  • 1
    On the server you can do what ever you want. Both GET and HEAD should NOT modify data on server. If you GET does modify something (a request statistic for example) it is up to you, if the HEAD request should do the same (I can imagine both situation, where it could make scenes). – 30thh Nov 16 '11 at 10:02
2

Is you question related to HTML, HTTP or server implementation of the request parser?

If you are speaking about HTML, the answer is "NO". HTML only supports GET or POST. If you try to create a form like

<form method="HEAD" action="http://ard.de">

the Firefox ignores the method attribute and sends the request as GET.

If you are speaking about HTTP, the answer is "YES". You can send the request with a query string like a GET-HTML-FORM does http://ard.de?param1=value&param2=value.

It is not specified, but as I understood the HTTP specification it is also not forbidden to sent the parameter in the body of the request (like POST-HTML-FORM usually does). It was discussed here.

If you are speaking about server side parser, you must mention it. J2EE 6 servlet stack implementation always parses the query string, but it parses the body only for POST request (not even for PUT request).

Community
  • 1
  • 1
30thh
  • 10,861
  • 6
  • 32
  • 42
1

Yes, a HEAD request can take parameters. However, RFC 2616 also says that a HEAD or a GET request should be Idempotent, that is, there are very strict limitations on the side effects that are allowed for such a request.

A GET or a HEAD request should only be used to retrieve data, NOT to store stuff on the server.

John Mellor
  • 12,572
  • 4
  • 46
  • 35
Mathias Schwarz
  • 7,099
  • 23
  • 28
  • Are you sure you meant what you said? "A GET...should NOT be used to retrieve data...on the server." – james.garriss Nov 15 '11 at 18:39
  • In any case, I think your answer contradicts the HTML specs, including HTML5, which specifically allows GETs and POSTs for form submissions. See http://dev.w3.org/html5/spec/Overview.html#form-submission-0. – james.garriss Nov 15 '11 at 18:45
  • You can use GET with forms that don't modify the server, for example search forms. Always use POST with forms that have side effects (e.g. adding/deleting/editing content, causing emails to be sent, etc). In other words, always use POST if it's not ok for the form to be accidentally submitted multiple times. – John Mellor Mar 13 '12 at 21:38
0

I suppose you can, but the HttpRequest implementation won't help you to parse the body of the request. And some proxies will possibly block such a "suspicious" paket.

In other words It is possible, but will be not conform with the standard.

30thh
  • 10,861
  • 6
  • 32
  • 42
  • "Do you mean parameter in a request body?" No. I mean parameters as query strings in the resource location. See the example request line I gave in my question. That is what a GET would do. – james.garriss Nov 15 '11 at 18:47
  • Heh. I see you've edited your response. But it still doesn't make sense. It's a HEAD; there is no body, so of course the body won't be parsed. – james.garriss Nov 15 '11 at 18:52