flockofcode
flockofcode

Reputation: 1819

Some confusion with GET/POST requests

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

Upvotes: 1

Views: 203

Answers (3)

Ray
Ray

Reputation: 21905

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.

Upvotes: 2

x0n
x0n

Reputation: 52430

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.

Upvotes: 1

Mark
Mark

Reputation: 11740

  • 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.

Upvotes: 4

Related Questions