Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it valid to combine a form POST with a query string?

I know that in most MVC frameworks, for example, both query string params and form params will be made available to the processing code, and usually merged into one set of params (often with POST taking precedence). However, is it a valid thing to do according to the HTTP specification? Say you were to POST to:

http://1.2.3.4/MyApplication/Books?bookCode=1234 

... and submit some update like a change to the book name whose book code is 1234, you'd be wanting the processing code to take both the bookCode query string param into account, and the POSTed form params with the updated book information. Is this valid, and is it a good idea?

like image 935
Jez Avatar asked Feb 05 '13 14:02

Jez


People also ask

Can you use a query string with a post request?

A POST request can include a query string, however normally it doesn't - a standard HTML form with a POST action will not normally include a query string for example.

What characters are allowed in query string?

The query component is a string of information to be interpreted by the resource. Within a query component, the characters ";", "/", "?", ":", "@", "&", "=", "+", ",", and "$" are reserved.

How do I pass query string?

To pass in parameter values, simply append them to the query string at the end of the base URL. In the above example, the view parameter script name is viewParameter1.


1 Answers

Is it valid according HTTP specifications ?

Yes.

Here is the general syntax of URL as defined in those specs

http_URL = "http:" "//" host [ ":" port ] [ abs_path [ "?" query ]] 

There is no additional constraints on the form of the http_URL. In particular, the http method (i.e. POST,GET,PUT,HEAD,...) used don't add any restriction on the http URL format.

When using the GET method : the server can consider that the request body is empty.

When using the POST method : the server must handle the request body.

Is it a good idea ?

It depends what you need to do. I suggest you this link explaining the ideas behind GET and POST.

I can think that in some situation it can be handy to always have some parameters like the user language in the query part of the url.

like image 196
ben75 Avatar answered Oct 04 '22 15:10

ben75