HTTP format Analysis

Source: Internet
Author: User
Tags unsupported

HTTP (hypertexttransferprotocol) is short for Hypertext Transfer Protocol. It is used to transmit WWW-based data. The Protocol followed by a browser and a web server is HTTP, for more information about the HTTP protocol, see rfc2616. The HTTP protocol uses the request/response model. The client sends a request to the server. The request header contains the request method, Uri, Protocol version, and message structure similar to mime containing the request modifier, customer information, and content. The server responds with a status line. The corresponding content includes the version of the Message Protocol, and the server information, entity metadata, and possible entity content are added to the success or error code.

HTTP messages include the request message sent from the client to the server and the response message sent from the server to the client. A protocol message consists of a start line, a header field, and an optional message body. HTTP/1.1 is the current standard protocol of the Internet, which is based on HTTP/1.1.

The format of the first action of the request message is as follows:
Method Request-Uri http-version/R/n

Method indicates the method for completing request-Uri. This field is case sensitive, including options, get, Head, post, put, delete, and trace. Methods get and head should be supported by all common Web servers, and implementation of all other methods is optional. The get method retrieves the information identified by request-Uri. The head method also retrieves the information identified by request-Uri, but does not return the message body during the response. The post method can request the server to receive entity information contained in the request and can be used to submit a form.

Request-Uri follows the URI format. When this field is asterisk (*), the request is not used for a specific resource address, but for the server itself.
HTTP-version indicates the supported HTTP Version. For example, HTTP/1.1.

The format of the first response message is as follows:
HTTP-version status-code reason-phrase/R/n

HTTP-version indicates the supported HTTP Version. For example, HTTP/1.1.
Status-code is the result code of three numbers, which is mainly used for automatic machine identification.
Status-code may have five different values:
1xx: Information Response class, indicating that the request is received and processed continuously
100 continue
101 Exchange Protocol
2XX: Successful response class, indicating that the action is successfully received, understood, and accepted
200 OK
201 created
202 receiving
203 non-authentication information
204 NO content
205 reset content
Part 1
3xx: redirect response class. To complete the specified action, you must accept further processing.
300 multi-Choice
301 permanent transfer
302 temporary transfer
303 see other
304 unmodified (not modified)
305 use proxy
4xx: client error. The client request contains a syntax error or cannot be correctly executed.
400 bad request)
401 unauthenticated
402 payment required
403 Forbidden)
404 not found)
405 method not allowed
406 not accepted
407 proxy authentication required
408 request timeout
409 conflict
410 failed
411 length required
412 condition failed
413 the Request Entity is too large
414 the request URI is too long
415 media types not supported
5xx: server error. The server cannot correctly execute a correct request.
500 Internal Server Error
501 not implemented (not implemented)
502 gateway failure
504 gateway timeout
505 HTTP Version Not Supported

Reason-phrase provides a simple text description for status-code. Reason-phrase is mainly used to help users understand.

1. The HTTP header domain includes four parts: Common header domain, request header domain, Response Header domain, and object header domain.

    A common header domain is a header domain supported by both request and response messages.

Including cache-control, connection, date, Pragma, transfer-encoding, upgrade, via, and other methods.

    Cache-control header field

Specify the cache mechanism for requests and responses. Cache Commands include no-cache, no-store, Max-age, Max-stale, Min-fresh, only-if-cached, response Commands include public, private, no-cache, no-store, no-transform, must-revalidate, proxy-revalidate, and Max-age.

    The date header field indicates the message sending time.

The description format of time is defined by rfc822. The time described in date indicates the world standard, such as date: Mon, 31dec200104: 25: 57gmt.

    The Pragma header field is used to contain specific instructions.

Pragma: No-cache is commonly used. The meaning of HTTP/1.1 is the same as that of cache-control: No-cache.

2. Request Header domain

The request header field allows the client to transmit request or additional information about the client to the server. The request header field may contain the following fields: Accept, accept-charset, accept-encoding, accept-language, authorization, from, host, if-modified-since, if-match, and if-none. -match, if-range, if-range, if-unmodified-since, Max-forwards, proxy-authorization, range, Referer, and User-Agent. Both parties need to support the expansion of the Request Header domain. If an unsupported Request Header domain exists, it is generally processed as an object header domain.

3. Host Header domain
The Host Header specifies the intenet host and port number of the requested resource (the default port can be omitted). It must represent the location of the original server or gateway of the request URL. The HTTP/1.1 request must contain the Host Header domain; otherwise, the system returns the status code 400.

4. referer header field

The referer header field allows the client to specify the source resource address of the request URI, which allows the server to generate a rollback linked list for login and Cache Optimization. He also allows abolished or erroneous connections to be tracked for maintenance purposes. If the requested URI does not have its own URI address, the Referer cannot be sent. If some Uri addresses are specified, this address is a relative address.

5. range header field

The range header field can request one or more sub-ranges of an object.
Indicates the first 500 Bytes: bytes = 0-499
Indicates the second 500 Bytes: bytes = 500-999
Indicates the last 500 Bytes: bytes =-500
Indicates the range after 500 Bytes: bytes = 500-
First and last Bytes: bytes = 0-0,-1
Specify the following ranges: bytes = 500-600,601-999.

However, the server can ignore this request header. If the unconditional get contains the range request header, the response will be returned with the status code 206 partialcontent) instead of 200 (OK ).

6. User-Agent header domain
The content of the User-Agent header field contains the user information that sends the request, which is generally the browser type of the client.

The typical request message is as follows:
Get http://www.wantsoft.com//r/n
HOST: www.wantsoft.com
Accept :*/*
Pragma: No-Cache
Cache-control: No-Cache
Referer: www.wantsoft.com
User-Agent: Mozilla/4.04 [En] (Win95; I; NAV)
Value Range: bytes = 554554-

The response header field allows the server to transmit additional information that cannot be placed in the status line. These fields mainly describe the server information and further information. The Response Header includes age, location, proxy-authenticate, public, retry-after, server, vary, warning, and WWW-authenticate. The expansion of the Response Header domain requires both parties to support the communication. If an unsupported Response Header domain exists, it is generally processed as an entity header domain.

Typical response message:

HTTP/1.0200ok
Date: Mon, 31dec200104: 25: 57gmt
Server: Apache/1.3.14 (UNIX)
Content-Type: text/html
Last-modified: Tue, 17apr200106: 46: 28gmt
Etag: "a030f020ac7c01: 1e9f"
Content-Length: 39725426
Content-range: bytes554554-40279979/40279980

7. Location Response Header domain
The location response header is used to redirect the receiver to a new URI address.

8. Server Response Header domain
The server response header contains the software information of the original server that processes the request. This domain can contain multiple product identifiers and comments. Product identifiers are generally sorted by importance.

9. Content-Type object header field
It is used to indicate the media type of the object to the receiver, specify the object media type sent by the Head Method to the receiver, or the request media type sent by the get Method to the content type set to "mime-type. Mime, that is, multi-task Internet Mail Extension (Multipurpose Internet Mail Extension). Some common content types are as follows:
Text/html: HTML document.
Text/plain: a plain text file.
Image/JPEG: JPEG image file.
Image/GIF: a GIF image file.
Image/TIFF: an image file in TIFF format.
Application/RTF: multi-information text format document.
Application/ZIP: PKZIP or WinZip compressed file.
Video/MPEG: Specifies the MPEG video file.
Video/quicktime: QuickTime video file.

10. The content-range object header is used to specify the insert position of a part of the entire object. It also indicates the length of the entire object. When the server returns a partial response to the customer, it must describe the response coverage and the length of the entire object. General format:

Content-range: bytes-unitspfirst-byte-pos-last-byte-pos/entity-Lety
For example, transfer the form of the header 500 byte field: Content-range: bytes0-499/1234 if an HTTP message contains this section (for example, content-range indicates the transfer range, and Content-Length indicates the number of bytes actually transmitted.

11. Last-modified Object Header
Specifies the last revision time of the content saved on the server.

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.