The learning of HTTP

Source: Internet
Author: User
Tags send cookies

What is the HTTP protocol

Protocol refers to the rules or rules that must be adhered to in communication between two computers in a computer communication network, and Hypertext Transfer Protocol (HTTP) is a communication protocol that allows Hypertext Markup Language (HTML) documents to be routed from a Web server to a client's browser

The appearance of history

There are three issues with the transport of the Web over a network:

    1. How the client knows where to find the data address---URI
    2. How the client gets the content after it knows the address---HTTP
    3. What form of content is being identified by the client---HTML
HTTP Request Components
    1. Request Line
    2. HTTP Header
    3. Content
1. Request Line

GET www.cnblogs.com http/1.1
The three parts are composed of:

    1. Request method (common with Get,post)
    2. Url
    3. HTTP version
2.HTTP Head

Three kinds

    1. Requests header (Request header)
    2. Normal header (general header)
    3. Entity header Typically, because a GET request does not always contain a content entity, there is no entity header.
3. Content

The third part exists only in the POST request because the GET request does not contain any entities.

HTTP Response Components
    1. Status line
    2. HTTP Header
    3. return content
1. Status line

http/1.1 OK (HTTP status, status code)

Status Code classification
    1. Information Classes (100-199)
    2. Response Successful (200-299)
    3. Redirect (300-399)
    4. Client Error (400-499)
    5. Server-side error (500-599)
return content

HTTP response content is not only HTML, but also other types, then how the browser correctly docking received information to process? This is determined by the media type, which specifically corresponds to the Content-type HTTP header. The format of the media type is: Large class/small class. There are 8 kinds:

    • application-(for example: Application/vnd.ms-excel.)

    • Audio (for example: Audio/mpeg.)

    • Image (for example: Image/png.)

    • Message (for example,: Message/http.)

    • Model (for example: MODEL/VRML.)

    • Multipart (for example: Multipart/form-data.)

    • Text (for example: text/html.)

    • Video (for example: Video/quicktime.)

HTTP Header

Four categories

1. Header (HTTP request header)

A request header is a header that is sent by the client to the server to help the service side better satisfy the client request. The request header can only appear in the HTTP request.

    • Accept:: Browser-side acceptable media types
    • Cookies
    • User-agent: Tells the HTTP server the name and version of the operating system and browser that the client is using.
    • Range
    • If-match-since: The last modification time of the browser-side cache page is sent to the server, and the server compares this time with the last modification time of the actual file on the server. If the time is the same, then return 304, the client uses the local cache file directly. If the time is inconsistent, 200 and the new file contents are returned. After the client receives it, it discards the old files, caches the new files, and displays them in the browser.
2. Response header (HTTP Response header)

The HTTP response header is the header that describes the HTTP response itself, which does not contain the header that describes the third part of the HTTP response, which is the HTTP message (this is partly the entity header)

    • Refresh timed Refreshes
    • Set-cookie: Used to send cookies to the client browser, each write cookie generates a Set-cookie.
3. Solid Head (Entity header)

is related to the content, so there is no post method and HTTP response in the request through the HTTP GET method.

    • Content-type
    • Content-length
    • Content-language
    • Conent-encoding
    • Content-md5
    • Expires: The browser will use the local cache within the specified expiration time; The last-modifies is used to indicate the last modification date and time of the resource.
4. Universal header (General header)

The HTTP itself can be described in the request/response.

    • Connection:http whether persistent connections such as:
    • 1.connection:keep-alive when a Web page opens, the TCP connection between the client and the server for transmitting HTTP data does not close, and if the client accesses the Web page on the server again, it will continue to use the established connection
      2.connection:close represents the completion of a request, the TCP connection between the client and the server for transmitting HTTP data is turned off, and the TCP connection needs to be re-established when the client sends the request again.
    • Date sent by date:http
    • TCP connection time where the keep-alive:http is located
    • Cache-control: whether to cache
HTTP features 1.http protocol is stateless

There is no correspondence between this request and the last request of the same client, and it is not known to the HTTP server that the two requests are from the same client. To solve this problem, the Web program introduces a cookie mechanism to maintain state.

2. Opening a Web page requires a browser to send many request

The server returns the data to the browser, and the browser interprets the data to find a lot of references such as CSS,JS. Then the request continues to be sent until all data has been downloaded

The 3.HTTP is TCP-based

HTTP is a transport-layer-based TCP protocol. So HTTP begins with a TCP connection before starting the transfer, and the TCP connection process requires a so-called "three handshake". After the TCP three handshake, a TCP connection is established, at which point the HTTP can be transmitted. An important concept is connection-oriented, where HTTP is not disconnected from the TCP connection between completion of the transfer.

      1. Http://www.cnblogs.com/CareySon/archive/2012/04/27/HTTP-Protocol.html
      2. Http://www.cnblogs.com/TankXiao/archive/2012/02/13/2342672.html

Learning from HTTP

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.