1. Introduction
HTTP is an object-oriented protocol belonging to the application layer, which is suitable for distributed hypermedia information System because of its simple and fast way. It was proposed in 1990, after several years of use and development, has been continuously improved and expanded. Currently used in the WWW is the sixth edition of Http/1.0, http/1.1 standardization work is in progress, and Http-ng (Next Generation of HTTP) has been proposed.
The main features of the HTTP protocol can be summarized as follows:
1. Support client/server mode.
2. Simple and fast: When a customer requests a service from the server, it simply transmits the request method and path. The request method commonly has, POST. Each method specifies a different type of contact between the customer and the server. Because the HTTP protocol is simple, the HTTP server's program size is small, so the communication speed is fast.
3. Flexible: HTTP allows the transfer of any type of data object. The type being transmitted is marked by Content-type.
4. No connection: The meaning of no connection is to limit the processing of only one request per connection. When the server finishes processing the customer's request and receives the customer's answer, the connection is disconnected. In this way, the transmission time can be saved.
5. Stateless: The HTTP protocol is a stateless protocol. Stateless means that the protocol has no memory capacity for transactional processing. A lack of state means that if the previous information is required for subsequent processing, it must be re-routed, which may cause the amount of data to be transferred per connection to increase. On the other hand, it responds faster when the server does not need the previous information.
2. HTTP request and Response
2.1 HTTP request--method
GET |
Request to get the resource represented by Request-uri |
POST |
Append new data to the resource identified by Request-uri |
HEAD |
Request for a response message header for a resource identified by Request-uri |
PUT |
The request server stores a resource and uses Request-uri as its identity |
DELETE |
Requesting the server to delete resources identified by Request-uri |
TRACE |
Request Server Loopback received request information, primarily for testing or diagnostics |
2.2 HTTP request--Common response code
Status code |
Describe |
Client request succeeded |
200 |
Ok |
Client request succeeded |
206 |
Partial Content |
Return part of the request entity |
301 |
Moved Permanently |
Target permanent movement |
60W |
Found |
Find Target (target is moved temporarily) |
304 |
Not Modified |
Target not modified |
400 |
Bad Request |
Client requests have syntax errors and cannot be understood by the server |
403 |
Forbidden |
The server received the request but refused to provide the service |
404 |
Not Found |
Request resource does not exist |
413 |
Request Entity Too Large |
Request entity too large |
500 |
Internal Server Error |
An unpredictable error occurred on the server that prevented the client from completing the request |
502 |
Bad Gateway |
Gateway error, which may be caused by network failure or excessive load. |
504 |
Gateway Timeout |
Connection timed out |
3. Common HTTP header fields
[Plain] View Plaincopy
- Accept (identifies entity types that the browser can accept)
- Accept-charset/accept-language (character set and language)
- Accept-encoding (Accept encoded format gzip or Deflat)
- Cache-control (Cache policy. Example: Cache-control:no-cache)
- Pragma (callout. Example: Pragma:no-cache)
- Connection (connection parameter.) Example: Connection:close)
- Date (day. Example: DATE:MON,31DEC200104:25:57GMT)
- Content-type (Identifies the entity type. For example: content-type:text/html. Mime.types file example)
- Transfer-encoding (transfer encoding. Chunk)
- Content-length (solid length)
- Set-cookie/cookie
- User-agent (Browser ID)
- Host (target host)
- Expires
- Last-modified
- Range/content-range
- Content-disposition
- Referer (reference, usually the URL of the previous visit)
4. HTTP protocol format and structure---examples
[Plain] View Plaincopy
- Get/index.shtml http/1.1
- Host:www.google.com
- user-agent:mozilla/5.0 (Windows; U Windows NT 5.1; ZH-CN; rv:1.9.0.5) gecko/2008120122 firefox/3.0.5
- accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
- accept-language:zh-cn,zh;q=0.5
- Accept-encoding:gzip,deflate
- accept-charset:gb2312,utf-8;q=0.7,*;q=0.7
- keep-alive:300
- Connection:keep-alive
- http/1.x OK
- Date:tue, 08:26:37 GMT
- server:apache/2.2.8 (Unix) php/5.2.6
- Accept-ranges:bytes
- Keep-alive:timeout=5, max=99
- Connection:keep-alive
- Transfer-encoding:chunked
- content-type:text/html; Charset=utf-8
HTTP protocol--Request and response