четвер, 26 серпня 2010 р.

Difference between get and post


I'm doing web programming for almost 5 years. But only today I discovered for myself what is difference between GET and POST. It's good that nobody at job interviews asked me what is difference between them.

The difference is very simple. The first request of the web page to the web server is called GET. All others are called POST.

That's why in C# for asp.net it is valid code:

if(!Page.IsPostBack) //this means we have GET
{
//do your code for page initialisation
}
else
{
//analyze requests for web browsers
}




According to book self training book from Microsoft Press usual steps is like this:
1. A user uses his or her Web browser to initiate a request for a Web server resource. (Hi or she initialize get)
2. HTTP is used to send a GET request to the Web server. (through web browser, like IE, FF, Chrome, etc...)
3. The web server   processes the GET request on the server (typically locating the requested code and running it). (it could be Apache, Kassinin, IIS, ...)
4. The Web server then sends a response back to the Web browser. The HTTP protocol is used to send the HTTP response back to the Web browser.
5. The user’s Web browser then processes the response (typically HTML and JavaScript) and renders the  web page for display to the user.
6. The user may then enter data and perform an action such as clicking a submit button that causes his or her data to be sent back to the Web server for processing.
7. HTTP is used to POST the data back to the Web server.
8. The Web server then processes the POST request (again, calling your code in the process).
9. The Web server then sends a response back to the Web browser. HTTP is used to send the HTTP response to the Web browser.
10. The Web browser again processes the response and displays the Web page to the user.



This process is repeated over and over during a typical Web application session.

2 коментарі:

  1. Another notes.
    There are two ways to send web page to server. As get, and as post. If to send it as get, then each time in command string it will be the form data will be added to command line as key-value pairs. If to use get, then it process will be avoided.

    As usually method GET is not recommended for using in asp.net due to:
    1. user can change parameters in command string and cause errors
    2. user after changes in command line can see something, which he wasn't intended to see
    3. GET is limited by length for 1024 characters (when using IE and IIS)

    When the POST verb is used, the data is placed into the message body of
    the request

    ВідповістиВидалити
  2. Also post allow to send up to 10 megabytes of data, which is much bigger. But it also has some side effects. If your user doesn't have high speed internet connection, he will say about developer a lot of not positive ideas

    ВідповістиВидалити