Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Post or Get, That is the question?

Status
Not open for further replies.

aojonesoa

Technical User
Apr 25, 2001
40
US
What would be a good example of when you would choose a GET method over a POST?

What would be a good example of when you would choose a POST method over a GET?

It appears (to me) the only difference is that the GET adds the variables to the URL and the POST doesn't (and querystring vs form).

There has to be something else to it, right?
 
Hi aojonesoa,

I always use POST because I find it not very elegant to have a long url filled with data which has no value to the client.

Second, and perhaps most important, sometimes as a developper you don't want the client to see what you are sending.

Gtz,

Kristof
 
That is kind of what I was thinking. But is it true that there is no other difference? Can I do everything with POST that I can with GET?
 
This is how POST and GET works(by the way, I made my own Web Server at home and I see everything in browser-server comunication)

GET (this is the default)
- the variables are added to the address with the (?=&) sintax. IE does URLEncode the string,Netscape doesn't(I mean a variabile like x="a b"is encoded like ?x="a%20b&..." by IE and like ?x="a b&" by Netscape)
- the server sends the variabiles to the parser(for example ASP.DLL) through the query string
- the variables are visible in the status line of the browser request header to the server.
- the variabiles can be read with QueryString.

POST
- the variabiles are sent to the server in the BODY of the browser request not in the HEADER,IE does URLEncode the string,Netscape doesn't.
- usually the server adds this variabiles to the environment variabiles(like %TEMP%) therefore you have a limit here depending on OS from the server, and the parser program(for example ASP.DLL) picks the from here.
- the variabiles can be read through the Form("variabile") member of the Request Object.

Soon I will post a trial version of my Web Server(it's description already exist) on my site(address below).

Hope this helps, s-)

Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
Hi,

I've done some digging and this is an explaination I came up with:

With the POST method, the browser sends the data in two steps: the browser first contacts the form-processing server specified in the action attribute, and, once contact is made, sends the data to the server in a separate transmission.

On the server side, POST-style applications are expected to read the parameters from a standard location once they begin execution. Once read, the parameters must be decoded before the application can use the form values. Your particular server will define exactly how POST-style applications can expect to receive their parameters.

The GET method, on the other hand, contacts the form-processing server and sends the form data in a single transmission step: the browser appends the data to the form's action URL, separated by the question mark character.


This is the definition of both methods as I found them.

Hope this clears it? :p

Kristof
 
Many people I know use POST for data-sensitive applications...wanting to hide the data submitted through the page. GET sends data through HTTP headers, POST sends data within the BODY.

Because of this, certain scrips people write rely on parameters passed through the GET method...like search scripts...people are fascinated by this...especially those in Perl. If you use WYSIWYG editors for ASP development like UltraDev or Visual InterDev, they'll recommend you just stick with POST.

Here's some good explanations I found for you:

 
Here's one more good from the fine folks @ O' Reilly:



HTTP Request Types

The request type is passed by the client to the server to indicate what the server should do with the URL that's also supplied by the browser. Although the HTTP specification details a number of request types, like PUT and DELETE, only two are supported by all servers and in common use: GET and POST. A GET request asks the server to "get" a piece of information, typically a document, and return it to the client. If the request includes any additional information, these are appended as arguments to the URL. A POST request, on the other hand, provides the server with information to be "posted" to the URL; typically, it's used to send the contents of an HTML form to the server, or to provide the server with information that's needed for back-end processing. The information itself is contained in the body of the request.

Most servers cannot handle data received from either the POST or GET methods internally. Normally, POST requests, as well as GET requests that also send data to the server, are handled by accessory programs or DLLs (CGI and ISAPI applications and ISAPI filters). Both POST and GET requests can return any kind of data of any size.

While it may seem when transmitting data to a web server that GET and POST are similar, one rule is hard and fast: A GET request must never change anything. Don't write an ASP script that makes changes to a database, for instance, in response to a GET request. The reason for this is discussed in greater detail in the following section, "Form Submission."

GET Versus POST

In the event that you're confused about the difference between these two methods, GET can be used to retrieve any document, POST cannot. On the other hand, both GET and POST can be used to pass data to the object indicated by the URL. When GET is used for this purpose, the data is included in the URL as the argument string; in order to extract this data with Win-CGI, you have to parse the argument string. When POST is used, the data is passed to the server in the body of the request message. So, in cases in which data is sent to the server, GET and POST differ in the method used to transmit that data.

Form Submission

A user enters input into the fields of a form. When the form is submitted, the data contained in each field of the form is transferred to the server, which then passes it to ASP. This data is sent in the format name=value, where name is the name assigned to the field by the NAME= attribute of the <INPUT> tag, and value is the value entered in that field. For example, if the user enters &quot;Archie&quot; in a field prompting for his first name, the browser may send along the string first_name=Archie.

If the form is written to use METHOD=GET, the form data is appended to the URL as an argument string. If the form contains many fields or if fields contain long strings of text, the complete URL can become very large and unwieldy. In addition, the limit of the number of characters submitted in a GET--typically about 2000--is much lower than in a POST.

If the form instead uses METHOD=POST, the name=value pairs are sent as the body of the request instead of being appended to the URL. In addition to the greater ease of handling of POST requests, most servers offer better performance when extracting data from the body of a request than from a URL in the request header.

Always use the POST method with forms that change something or cause any irreversible action (most do). POST is safer and more efficient; GET should never be used to change anything. In developing your ASP scripts, you can decide whether you want to support data passed to your program using the GET method.
 
I just want to add a couple more

1.You get that confirmation of posting message box from POST method on Netscape. It's sometimes annoying to have that message if you'd like to pass on variables from page to page. GET method is preferred.

2.Some old browser may have limitation on the size of the URL. POST method is then recommended.

I think it depends on your case to choose which method to use. I wouldn't just stick to one.

Regards
 
just to add my two penny worth.

I use Post where all data is static i.e. the data is the same no matter who comes to the page or what data is displayed on the page

But I use the URL (Get for better want of a word) to pass data where I have several links on the page, each of which is passing different data so Post method would not work.

But otherwise would always use Post Saturday 12.00
im6.gif
im2.gif
im2.gif
20.00
im5.gif
im4.gif
im7.gif
3.00am
im8.gif
Sunday [img http
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top