The. Net Framework Development HTTP protocol

Source: Internet
Author: User
Tags session id

First, the basic principle of HTTP

how the 1.HTTP protocol works
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The HTTP protocol is based on the request/response paradigm. After a client establishes a connection to the server, it sends a request to the server in the form of a Uniform Resource Identifier, protocol version number, followed by MIME information including the request modifier, client information, and possible content. After the server receives the request, it gives the corresponding response information in the form of a status line that includes the protocol version number of the information, a successful or incorrect code, followed by MIME information including server information, entity information, and possible content.
It is divided into four processes, in the HTTP protocol, the server is the part that provides the HTTP service, the client refers to the browser you use or download tools and so on. In the communication, the client makes a request connection, the server establishes the connection, and then the client makes an HTTP request (request) and the server returns the response information (Respond), thus completing an HTTP operation.

HTTP Status Detection (HTTP Header)

The meaning of the HTTP protocol status Code representation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1XX reserved
2XX indicates that the request was successfully received by
3XX request further refinement of requests for completion of customer requests
4XX Customer Error
5XX Server Error

The basic concept of 2.uri,url,urn

URIs define a Uniform resource identity in an abstract, high-level concept, whereas URLs and urns are the exact way the resource is identified. URLs and urns are all a kind of URI. a URI instance can represent an absolute or relative, as long as it conforms to the syntax rules of the URI. The URL class not only conforms to semantics, but also contains information that locates the resource, so it cannot be relative, and the schema must be specified.

To summarize: A URL is a specific URI that uniquely identifies a resource and provides information to locate the resource. A URI is a semantic abstraction that can be absolute or relative, and the URL must provide enough information to locate it, so it is absolute, and the usual relative URL is for another absolute URL, which is essentially absolute.

Illustrate the difference between a URL and a URI:

The URI is from the virtual root path that can be
The URL must be an entire link that can be uniquely targeted to the page based on the URL.
such as URL http://zhidao.baidu.com/question/68016373.html
URI is/question/68016373.html (as long as the information can be identified)
On the Baidu side of the server to make http://zhidao.baidu.com/into a virtual path
The root

Structure of the 3.URL:

4.HTTP is a stateless protocol as well as cookies and session applications:

After the client sends an HTTP request and receives a server-side response, the connection is disconnected and the next access is independent of the previous access, so if the client's information needs to be maintained, the state data must be maintained on the server side.

HTTP is an understanding of the stateless protocol:

The state of the Protocol refers to the ability of the next transmission to "remember" the transmission of this information. HTTP is a stateless protocol, with two consecutive requests for the same session that are not known to each other, and they are parsed by the newly instantiated environment, which does not save any information about the session, except that the application itself may already be stored in the global object.

HTTP is not to maintain the information transmitted by this connection for the next connection.

Stateless means when the browser sends a request to the server, the server responds, but the same browser sends the request to the server, he will respond, but he does not know that you are just that browser, simply said that the server will not remember you, so is a stateless protocol.
DNS is a stateful protocol.

After the advent of a Web application in which the client interacts dynamically with the server, the HTTP stateless feature seriously hinders the implementation of these applications, after all the interaction needs to be followed, and the simple shopping cart program knows what the user has chosen before. As a result, two techniques for keeping the HTTP connection state are created, one is a cookie and the other is a session.

A cookie is a solution that maintains state through the client. By definition, a cookie is a special message that is sent to the client by the server, which is stored as a text file on the client, and then each time the client sends a request to the server, the special information is brought. Let's be more specific: When a user uses a browser to access a Web site that supports cookies, the user provides personal information including the user's name and submits it to the server, and the server sends back the personal information when it sends the corresponding hypertext to the client. Of course, this information is not stored in the HTTP response body (Response body), but is stored in the HTTP response header (Response header), when the client browser receives a response from the server, the browser will store this information in a unified location, For the Windows operating system, we can find the stored cookie from: [System disk]:\documents and settings\[user name]\cookies directory, and since then, when the client sends the request to the server, will send the corresponding cookie back to the server again. This time, the cookie information is stored in the HTTP request header.
With the implementation of a technology such as cookies, when the server receives a request from the client's browser, it is able to generate the client-specific information by analyzing the cookie stored in the request header, which dynamically generates the content corresponding to that client. Usually, we can see the "Please remember Me" option from the login screen of many websites, if you check it and then log in, then the next time you visit the site will not need to repeat the cumbersome login action, and this feature is implemented through a cookie.
A solution that is relative to a cookie is the session, which is maintained by the server. Since the term session contains a lot of semantics, it is necessary to clarify the meaning of the session here. First, we usually translate sessions into conversations, so we can refer to a series of interactions between the client browser and the server as a session. From this semantics, we will refer to the duration of the session, what is done during the session and so on, and second, the session refers to the server side for the client to open up the storage space, in which the information is used to hold the state. From this semantics, we will refer to what is stored in the session, how to get the matching content from the session according to the key value.
To use the session, the first step is of course to create a session. So when is the session created? Of course, it is created in the process of running the server-side program, the different language implementation of the application has different methods to create the session, and in Java by calling HttpServletRequest's GetSession method (using True as a parameter) created. When the session is created, the server generates a unique session ID for the session, and the session ID is used to regain the session that was created in the subsequent request, and after the session is created, You can call the session related methods to add content to the session, which will only be saved in the server, sent to the client only session ID, when the client sends the request again, the session ID will be taken, Once the server accepts the request, it will find the corresponding session based on the session ID, which is used again. Formally, the state of the user is maintained. The content of the session is also more, in the future post, I will continue to tell.

In summary, HTTP itself is a stateless connection protocol, in order to support the interaction between the client and server, we need to use different technologies for the interactive storage state, and these different technologies are the cookie and session.

5.Http structure of request and response:

(1) Structure of the HTTP request

(2) Structure of the HTTP response

(3) Get methods and Post methods for Http

Ii.. NET classes using the HTTP protocol

1.. The HTTP-related classes in net:

2. Synchronous calls and asynchronous calls

Synchronization: Submit request, wait for server processing, and then return to processing. During this period the client browser cannot do anything.

Asynchronous: The request is processed through event triggering, server processing (which is still something the browser can do).

Give a vivid example:

Synchronization is when you ask me to eat, I hear you go to dinner, if not heard, you keep barking until I tell you to hear, to go to dinner together.

Async is you call me, and then go to dinner, I can get the news immediately, may wait until after work to eat.

So, if I ask you to eat in a synchronized way, ask me to eat with the Async method, so you can save money.

For example, when the phone is synchronized, texting is asynchronous.

In the design of the ordinary B/s mode is synchronous, and Ajax technology is asynchronous, of course, Xmlhttpreques has the option of synchronization.

3,. NET about HTTP specific Code development examples

(1), synchronous request

(2) Asynchronous request: The benefit of an asynchronous request is that it does not block the current thread, but is slightly more complex than the synchronization request and at least two callback methods are added to get the asynchronous event.

Reference: Http://wenku.baidu.com/link?url= Rd3garvjeyzveotslsyjxu2wpbzjimoxsyxiut-cy0ehnmqicjsb7ukzcjibcfbxagagfmdga32rdexf1ld-d-1dlz1cp_lmfermjbfpdro

The. Net Framework Development HTTP protocol

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.