I have a doubt in Mikalai Zaikin notes regarding the request parameters. Below is the statement from the notes:
Data from the query string and the post body are aggregated into the request parameter set. Query string data is presented BEFORE post body data. For example, if a request is made with a query string of a=hello and a post body of a=goodbye&a=world, the resulting parameter set would be ordered a=(hello, and a post body of a=goodbye&a=world, the resulting parameter set would be ordered a=(hello, goodbye, world).
my doubt is:
How is it possible to send the data from query string (means Get request) and in body (means POST request) at the same time?
I'm sure that it's only possible to use either HTTP GET method or POST method but you just cannot use both at the same time as you already said.
But I think it's possible to make a POST request with POST data and at the same time give additional parameters in the URL you're using to submit your form data to. This is the only possibility I could imagine although I've never tried this. And usually you decide to use POST or GET depending on the the kind of request (idempotent request should use GET, others POST).
And I'm unsure about the behavior of the servlet implementation, too. I don't even know if GET parameters are honored if you use the POST method. Hopefully someone knows in more detail...
posted 12 years ago
Thanks for your reply Macro.
Originally posted by Marco Ehrentreich:
But I think it's possible to make a POST request with POST data and at the same time give additional parameters in the URL you're using to submit your form data to.
This statement theoritically looks fine,but how can we practically send a POST request and append some query string to the URL at the same time? because we can append query string either by appending it to the URL directly in the browser (in which case the request will be GET only) or in any href location on our HTML or JSP page with the URL already appended by the query string,(and in this case again it will be a GET request only) and if we send a POST request then I dont see any method to append explicitly the query string with the request.
Could Anybody else please share his/her knowledge on this?
It's possible to have an URL that has parameters in the action attribute of a form that uses POST.
Note that there is no ordering of parameters, though (which you mentioned in the first post). Any ordering you perceive there to be is accidental, and may change from between browsers or between servers.
you can give an URL with parameters as an action for your form I'd say... But as I already said this wouldn't be a real GET+POST request anyway because it's of course not possible to use two different HTTP methods like GET and POST in one real request.
You could additionally modify your request data using intercepting filters like Devasani said. Anyway in your servlet all parameters are treated equal and can be accessed using getParameter() (besides reading and parsing the whole body) so there has to be something happening before which might like a filter.
Or perhaps it's simply an error or an inaccuracy in the book!
Is the valid post request and give the expected result. I thing the GET request is using the Query String mechanism to pass the data to server, but Query String is not restricted to GET request, You can use it with POST method also though it is displayed in browser window.