views:

53

answers:

3

a) Based on what information does web application decide whether a particular request is a GET request? Simply by checking whether requested url contains any query string parameters?

b) When page http://some_domain/A.aspx is first requested (either by clicking a link element<a..> or by manually entering URL into address bar), I assume it is neither a POST or a GET request?

c) If users manually enters into Address toolbar url http://some_domain/A.aspx?ID=100, will web application considered a request as a GET request, even though query string values weren’t extracted ( by browser) from FORM elements?

d) Assuming we request http://some_domain/A.aspx?ID=100, will on postback browser request url http://some_domain/A.aspx?ID=100 or just http://some_domain/A.aspx?

e) Assuming page http://some_domain/A.aspx?ID=100 has FORM’s method attribute set to POST, but its url also contains some query string variables, then is on postback a request considered a GET or a POST?

Thank you

+4  A: 
  • a) It's a GET if the browser sent the GET verb in the HTTP request. Likewise for POST.
  • b) Both of the situations you describe will result in a GET request.
  • c) GET and POST are independent of query string, i.e. either can include or not include query string variables.
  • d) Because the original request included the querystring variables, the postback will again include those variables. The URL with the variables is a "different" URL than the one without.
  • e) If the form's method is POST, then it's a POST, regardless of what the URL contains. The query string variables are not related in any way to whether it's a GET or a POST.
Mark
re: d) this is not quite right. It depends on whether or not the FORM tag has an ACTION element.
x0n
@x0n: Yes, you're technically correct, you could "override" the URL with an action element. That's not the default case, however, and the user would have to specifically set that up.
Mark
"...you could "override" the URL with an action element. That's not the default case, however, and the user would have to specifically set that up."So if we don't explicitly specify FORM's action attribute, then by default this attribute is set to url of an original request?
flockofcode
"c) GET and POST are independent of query string, i.e. either can include or not include query string variables."What's the point of browser specifying first request as GET , since GET/POST are used with the way FORM data is submitted, while in my exqample on first request no FORM data was submitted?
flockofcode
@mark the only type of correct is correct, technical or not. ;-)
x0n
@flockofcode yes, if the form tag does not have an action (default for asp.net for example) then the postback url will include the querystring, if present.
x0n
Since GET/POST are used with the way FORM data is submitted and since in my example on first request no FORM data is submitted, is there really a point in browser specifying first request as a GET?
flockofcode
Every request is a GET unless it's some other kind of request (like POST, HEAD, PUT, etc, etc, etc). In the simple case, you can think of GET as the "default" request type. When you're using a form, the "post" request may be a GET, or it may be a POST, depending on the method="" attribute of the form.
Mark
thank you all for your help
flockofcode
+1  A: 

a) it knows from the HTTP verb used by the browser

b) it's a GET

c) it's still a GET

d) if the <FORM> tag has no ACTION attribute, it will include the query string. If it has an explicit ACTION attribute, it will be whatever that URL is.

e) it's a POST.

x0n
"d) if the <FORM> tag has no ACTION attribute, it will include the query string. If it has an explicit ACTION attribute, it will be whatever that URL is." In other words, if we don't explicitly specify FORM's action attribute, then by default this attribute is set to url of an original request
flockofcode
@flockofcode: correct.
x0n
+2  A: 

The GET or POST info is extracted from the request - the application does not decide what kind of request it it, it reads it from the request itself. For example, the first line of a request may look like this:

GET http://www.mysite.com 

The browser send this info to the app. Links are always GET requests. Your app can decide how a browser will respond to form submissions by setting the form's method attribute o GEt or POST.

I suggest you download Fiddler so you can see the raw request data for yourself.

Ray
+1 for suggesting fiddler
Chris Lively