HTTP protocol Basics

Source: Internet
Author: User
Tags local time ranges unsupported

HTTPProtocol Basics(a)

HTTP (hypertexttransferprotocol) is the abbreviation of Hypertext Transfer Protocol, it is used to transmit data of WWW mode, please refer to RFC2616 for details of HTTP protocol. The HTTP protocol uses a request/response model. The client sends a request to the server that contains the requested method, URI, protocol version, and a mime-like message structure that contains the request modifiers, customer information, and content. The server responds with a status line, which includes the version of the message protocol, the success or error code plus the containing server information, entity meta information, and possible entity content.
Typically, HTTP messages include the client's request message to the server and the server's response message to the client. The two types of messages consist of a starting row, one or more header fields, and an empty row and an optional message body that is just the end of the head field. The HTTP header domain includes a universal header, a request header, a response header, and an entity header four parts. Each header field consists of a domain name, a colon (:), and a field value of three parts. Domain names are case-insensitive, field values can be added to any number of spaces, and header fields can be extended to multiple lines, at the beginning of each line, with at least one space or tab.

Universal Header Field

The Common header field contains the header fields supported by both the request and response messages, and the Common header field contains Cache-control, Connection, Date, Pragma, transfer-encoding, Upgrade, Via. Extensions to the common header domain require both sides of the communication to support this extension, and if there are unsupported common header domains, they will normally be treated as entity headers. The following is a brief introduction to a few common header domains used in UPnP messages.

Cache-control header Field

CACHE-CONTROL Specifies the caching mechanism that the request and response follow. Setting Cache-control in a request message or in a response message does not modify the caching process during another message handling process. The cached instructions at request include No-cache, No-store, Max-age, Max-stale, Min-fresh, only-if-cached, and the instructions in the response message include public, private, No-cache, No-store, No-transform, Must-revalidate, Proxy-revalidate, Max-age. The instructions in each message have the following meanings:

Public indicates that the response can be cached by any buffer.

Private indicates that the entire or partial response message for a single user cannot be handled by the shared cache. This allows the server to simply describe a partial response message from the user, which is not valid for other users ' requests.

No-cache indicates that a request or response message cannot be cached

No-store is used to prevent important information from being inadvertently released. Sending in a request message will not use caching for both request and response messages.

Max-age indicates that the client can receive a response that is not longer than the specified time in seconds.

Min-fresh indicates that the client can receive response times that are less than the current time plus a specified time.

Max-stale indicates that the client can receive response messages that exceed the timeout period. If you specify a value for the Max-stale message, the client can receive a response message that exceeds the specified value for the timeout period.

Date Header Field

The Date header field represents the time when the message was sent, and the description format of the time is defined by rfc822. For example, Date:mon,31dec200104:25:57gmt. When the time represented by the date represents the world standard, it is converted to local time and needs to know the time zone in which the user is located.

pragma header field

The Pragma header field is used to contain implementation-specific instructions, most commonly pragma:no-cache. In the http/1.1 protocol, it has the same meaning as Cache-control:no-cache.

Request message

The first behavior of the request message is in the following format:

Methodsprequest-urisphttp-versioncrlfmethod indicates that the field is case sensitive for Request-uri completion, including options,, POST, put, DELETE , TRACE. The method get and head should be supported by all common Web servers, and the implementation of all other methods is optional. The GET method retrieves the information identified by the Request-uri. The head method is also to retrieve the information identified by the Request-uri, except that the message body is not returned when responding. The Post method can request the server to receive entity information contained in the request, which can be used to submit the form and send messages to newsgroups, BBS, mail groups, and databases.

The SP represents a space. Request-uri follows the URI format, which, when Cheweishing (*), describes the request not for a particular resource address, but for the server itself. Http-version represents a supported version of HTTP, for example, http/1.1. CRLF represents a line feed return character. The request header domain allows the client to deliver additional information about the request or 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, If-none-match, If-range, If-range, If-unmodified-since, Max-forwards, Proxy-authorization, Range, Referer, User-agent. The extension of the Request header field requires both communication support, and if an unsupported request header field exists, it will normally be treated as an entity header domain.

A typical request message:

Gethttp://download.microtool.de:80/somedata.exe

Host:download.microtool.de

accept:*/*

Pragma:no-cache

Cache-control:no-cache

referer:http://download.microtool.de/

User-agent:mozilla/4.04[en] (win95;i; NAV)

range:bytes=554554-

The first line of the previous example indicates that the HTTP client (possibly the browser, the download program) obtains the file under the specified URL through the Get method. The brown section represents the information for the Request header field, and the green section represents the generic head section.

Host Header Field

The Host header field specifies the Intenet host and port number of the requesting resource, and must represent the location of the original server or gateway that requested the URL. The http/1.1 request must contain a host header domain or the system will return with a 400 status code.

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 fallback list that can be used to log in, optimize cache, and so on. He also permits the abolition or wrong connections to be tracked because of maintenance purposes. If the requested URI does not have its own URI address, Referer cannot be sent. If a partial URI address is specified, this address should be a relative address.

Range header Field

The Range header field can request one or more child scopes for an entity. For example

Represents the first 500 bytes: bytes=0-499

Represents a second 500 byte: bytes=500-999

Represents last 500 bytes: bytes=-500

Represents 500 bytes after range: bytes=500-

First and last byte: Bytes=0-0,-1

Specify several ranges at the same time: bytes=500-600,601-999

However, the server can ignore this request header, and if the unconditional get contains the range request header, the response is returned in status Code 206 (partialcontent) instead of (OK).

User-agent header Field

The contents of the User-agent header field contain the user information that made the request.

Response message

The first behavior of the response message is in the following format:

Http-versionspstatus-codespreason-phrasecrlf

Http-version represents a supported version of HTTP, for example, http/1.1. Status-code is a three-digit result code. Reason-phrase provides a simple text description for Status-code. Status-code is mainly used for automatic machine identification, reason-phrase is mainly used to help users understand. The first number of Status-code defines the category of the response, and the latter two digits do not have a classification effect. The first number may take 5 different values:

1XX: Information response class, which indicates receipt of a request and continues processing

2XX: Handling a successful response class, indicating that the action was successfully received, understood, and accepted

3XX: Redirect Response class, in order to complete the specified action, you must accept further processing

4XX: Client error, customer request contains syntax error or is not properly executed

5XX: Service-side error, server does not perform a correct request correctly

The Response header field allows the server to pass additional information that cannot be placed in the status row, which mainly describes the server's information and Request-uri further information. The Response header field contains age, Location, proxy-authenticate, Public, Retry-after, Server, Vary, Warning, Www-authenticate. The extension of the Response header field requires both communication support and, if an unsupported response header field exists, it will normally be treated 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

The first line of the previous example indicates that the HTTP server responds to a GET method. The brown section represents the Response header field information, the green section represents the generic header section, and the red section represents the information for the Entity header field.

Location response Header

The location response header is used to redirect the recipient to a new URI address.

Server response Header

The server response header contains software information for the original server that processed the request. This field can contain multiple product identities and annotations, and product identities are generally sorted by importance.

Entity

Both the request message and the response message can contain entity information, and the entity information is generally composed of the entity header domain and the entity. The Entity header field contains the original information about the entity, and the entity headers include allow, Content-base, content-encoding, Content-language, Content-length, Content-location, CONTENT-MD5, Content-range, Content-type, Etag, Expires, Last-modified, Extension-header. Extension-header allows clients to define new entity headers, but these domains may not be recognized by the recipient. An entity can be an encoded byte stream encoded by content-encoding or content-type, and its length is defined by content-length or Content-range.

Content-type Entity Header

The Content-type entity header is used to indicate the media type of the entity to the receiver, specify the entity media type to which the head method is sent to the receiver, or the request media type sent by the Get method Content-range the entity header

The Content-range entity header is used to specify the insertion position of a portion of the entire entity, and he also indicates the length of the entire entity. When the server returns a partial response to the customer, it must describe the scope of the response coverage and the entire entity length. General format:

Content-range:bytes-unitspfirst-byte-pos-last-byte-pos/entity-legth

For example, the form of a 500-byte secondary field for the transport header: content-range:bytes0-499/1234 If an HTTP message contains this section (for example, a response to a range request or a range of overlapping requests), Content-range represents the range of the transfer, Content-length represents the actual number of bytes transferred.

Last-modified Entity Header

Last-modified The entity header specifies the last revision time for content saved on the server.

HTTPProtocol Basics(two)

The HTTP protocol defines how file transfer is communicated between the server side and the client. The current version of the HTTP protocol is Http1.1. RFC 2616 describes the specific information for the HTTP protocol.

This protocol has become a standard between browsers and Web sites.

How the bottom is interacting when I surf the internet.

When a visitor clicks on a hyperlink, a URL is submitted to the browser. Through this URL, the browser will know to link to the site and to obtain a specific page file (also may be a picture, a PDF file).

The basis of HTTP work is to connect a server and start transferring files to the browser.

Basic process of HTTP transmission

In the process of HTTP transmission, a requester called a client requests a file from the server.

The most basic process is:
1 The client connects a host;
2 The server receives the connection,
3 The client requests a file,
4 The server sends an answer.

Instance

Let's look at a few typical processes

First, we want to visit this page. Typing "http://www.maketop.net/resource/rs_041112_02.php" in the browser. The browser will connect Www.maketop.net and then send:

>> get/resource/rs_041112_02.php Http1.1
>> Host:www.maketop.net
>> accept:image/gif, Image/x-xbitmap, Image/jpeg, Image/pjpeg,
>> Accept-language:en
>> Accept-encoding:gzip, deflate
>> user-agent:mozilla/5.0 (Windows; U Windows NT 5.1; rv:1.7.3) gecko/20040913 firefox/0.10
>> connection:keep-alive
>>

Explanation: The browser requests the page "/resource/rs_041112_02.php". and use the HTTP1.1 protocol. And tell the server that your browser is Firefox0.10. The operating system is Windows XP. The browser wants to keep a connection to www.maketop.net and requests to get more files, including pictures in the Web page. Translated into languages above are:

>> obtain/resource/rs_041112_02.php with HTTP1.1 protocol
>> access to the host is: Www.maketop.net
>> received documents including: Image/gif, Image/x-xbitmap, Image/jpeg, Image/pjpeg,
>> the language used is: en
>> the encoding (which the browser can explain) is: gzip, deflate
>> User's browser information: Windows XP operating system firefox/0.10 Browser
>> Stay Connected: Also go to the picture
>>



Www.maketop.net server sends a response:

<< http/1.1 OK
<< Date:mon, Mar 19:12:16 GMT
<< server:apache/1.3.31 (Unix) mod_throttle/3.1.2
<< Last-modified:fri, Sep 2004 14:16:18
<< ETag: "Dd7b6e-d29-39cb69b2"
<< accept-ranges:bytes
<< content-length:3369
<< Connection:close
<< content-type:text/html
<<
<< File content goes here

The browser also obtains server information from the server's response: for example, running in Apache.
The above translates into the language above is

<< HTTP1.1 Agreement Method effective
<< Current time: Mon, Mar 19:12:16 GMT
<< Server is: apache/1.3.31 (Unix) mod_throttle/3.1.2
<< Last modified: Fri, SEP 2004 14:16:18
<< ETag: "Dd7b6e-d29-39cb69b2"
<< accept-ranges:bytes
<< content-length:3369
<< Connection:close
<< content-type:text/html
<<
<< File content goes here

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.