HTTP protocol Knowledge Collation

Source: Internet
Author: User
Tags response code

HTTP protocol

As a web developer, it is necessary to understand the knowledge of some HTTP protocols. This article simply introduces the knowledge of the HTTP protocol, if there is a wrong place, I hope you correct.

What is the 1.HTTP protocol?
    • The HTTP protocol is an application-level protocol. Specifies the communication specification between the browser and the server. TCP connection is usually used.
2.HTTP 1.0, 1.1 ways to connect.
    • In HTTP 1.0, the browser and server use a short connection, the response is complete, immediately disconnect.
    • Request process: 3 handshake, request, response, disconnect.
    • HTTP does not save the connection, the benefit: The server can handle more connections, but each time a connection is established, the processing speed is reduced.
    • Now the mainstream version is HTTP 1.1, in HTTP 1.1 we use a long connection, a request after the end of the continuous open, continue to request.
URL of the 3.HTTP protocol

Format of the URL:

http://host[":" Port][abs_path]

    • Host: Represents the hostname or IP address
    • Port: Port number, default 80
    • Abs_path: The URL of the request resource, if not, fill in "/", usually the browser will help us to complete automatically. Eg:1, Input: www.cnblogs.com browser automatically converted to: http://www.cnblogs.com/
4. HTTP request 4.1 Request message Format:

    • The HTTP request consists of 3 parts: The request line, the request header, and the request body.
    • SP represents spaces, CRLF for line breaks
    • The browser must send the request in this format in order for the server to parse and respond correctly.
4.2 Sample Request Message

4.3 Request method
    • Get request gets the resource identified by the Request-uri
    • Post appends new data to the resource identified by Request-uri, and is often used to submit a form.
    • HEAD request Gets the response message header for the resource identified by Request-uri
    • PUT Request server stores a resource and uses Request-uri as its identity
    • Delete Request server deletes the resource identified by the Request-uri
    • TRACE requests the server to echo received request information, primarily for testing or diagnostics
    • CONNECT reserved for future use
    • Options request the performance of the query server, or query for resource-related choices and requirements

Get and post are the most commonly used methods, in short, the former is used to obtain data, which is used to submit data.

5. HTTP Response 5.1 Response message Format:

    • The HTTP response is also made up of 3 parts: Response line, response header, response body
    • Response Line: Status code indicates the state code of the response, and description is the descriptive information.
    • The same SP represents a space, a CRLF represents a newline,
    • The response must be sent to the browser in this canonical format for the browser to parse and display correctly.
5.2 Example of Response message

5.3 Response Code

Paragraph 200 is a success; Paragraph 300 requires further processing of the request, 400 indicates a client request error, and 500 is a server error Common response codes:

    • "$": OK
    • "302": Found redirect.
    • "+": Bad Request error requests, incorrect HTTP protocol request issued
    • "403": Forbidden Forbidden
    • "404": Not Found was not found. Demo Access a nonexistent page read the paper
    • ' $ ': Internal Server error Server internal errors. The presentation page throws an exception.
    • "503": Service unavailable. The average number of visitors is too large.

PS: At the end of the article will provide you with a copy of the HTTP status Code Daquan document.

6. HTTP message Header

The HTTP message header is divided into 4 classes: normal header, request header, response header, entity header Each header field consists of a name + ":" + a Space + value, and the name of the message header field is case-insensitive.

6.1 Normal Header

Information that is applied to all request and response messages and is not related to the body of the request is stored in the normal header.

    • Cache-control:no-cache (used to indicate that a request or response message cannot be cached)
    • Date Normal header field indicates the day and time the message was generated
    • Connection:close/keep-alive (if long connection is turned on)
6.2 Request Header

additional information about the client passing the request to the server and information about the client itself is stored in the request header Common Request headers:

    • Accept:text/html,application/xhtml+xml,application/xml; Specifies which types of information the client accepts.
    • accept-charset:iso-8859-1,gb2312 the character set accepted by the client (by default, any character set can be accepted.) )
    • ACCEPT-ENCODING:GZIP,DEFLATE,SDCH acceptable content encoding. (the default is that various content encodings are acceptable.) )
    • ACCEPT-LANGUAGE:ZH-CN,ZH Specifies the language. (All languages are accepted by default.) )
    • Authorization is used to prove that a client has permission to view a resource
    • Host:www.cnblogs.com The Internet host and port number of the requested resource (default port number: 80) This header is required
    • user-agent:mozilla/4.0 (compatible; MSIE6.0; Windows NT 5.0) operating systems, browsers, and other properties
6.2 Response Header

The response header allows the server to pass additional response information that cannot be placed in the status line, as well as information about the server and the next access to the resources identified by Request-uri. Common response headers:

    • The Location response header field is used to redirect the recipient to a new position
    • server:apache-coyote/1.1 Server information
6.3 Entity Header

both request and response messages can send an entity. Common entity headers:

    • Content-encoding:gzip content Encoding
    • CONTENT-LANGUAGE:ZH-CN language
    • Content-length:10 Length of entity body
    • content-type:text/html;charset=gb2312 type of return data
    • The Last-modified Entity header field is used to indicate the last modification date and time of the resource.
    • expires:thu,15 SEP 2006 16:23:12 GMT Response Date and time of expiration.
Reference documents

HTTP protocol detailed HTTP status code Daquan document download content-type document download

Http://www.cnblogs.com/simple-blog/p/4377647.html

HTTP protocol Knowledge Collation (RPM)

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.