HTTP protocol packet format Detailed -HTTP

 

 

There are two HTTP protocol packets: request packets and response packets

A request packet

The following is a typical request packet:

 Each row consists of a carriage return and line feed end, the last line of extra plus a carriage return.

 

The first line of the HTTP request message is called the request line , the back section called the header row.

1, request line:

Request line of three fields: the method field, URL field, HTTP version field.

Method field possible values: GET, POST, HEAD, PUT and DELETE.

Most of the HTTP request is the GET method. When the browser requests an object, using the GET method, the URL request with the object ID field.

2, the header row

Host: 127.0.0.1: indicates the host object is located, although there are already a host TCP connection exists, but the information provided by the bank's Web proxy cache is required.

User-Agent: Acting indicated, is the type of browser. This proxy server can effectively send different versions of the same real object for different types of users.

Accept-Language: zh-CN: presentation syntax version. If the server is no such object, it will send its default version.

Connection: close: close it asks the server after the connection after sending the requested object.

 

HTTP request generic request format (discussed below solid body)

Solid body (entity body):

When you use the GET method entity experience is empty, the entity will use the body when using the POST method. When the form is submitted, the POST method will be used (e.g., a search keyword inputted in a search engine), the entity contained in the specimen is the value entered by the user in the form field.

While the POST method to use physical body, but "with form generation request packet does not have to use the POST method":

HTML forms often use the GET method, the form field in the URL of the requested input data includes, for example, a form using the GET method and BBB aaa has two fields, so the structure is such that the URL: www.xxx. com / admin? aaa & bbb (very common, when browsing the web can take note)

 

Here are some additional methods:

HEAD method, similar to the GET, HEAD server receives a request, it responds with a HTTP message, but not the anti-back request object, commonly used in debug trace.

PUT method: Path (directory) is often used in conjunction with Web publishing tools, he allows users to upload specified object to the specified Web server, which is also the same Web application server used to upload objects,

DELETE method: allows users or applications remove objects on the Web server.

 


 

Second, the response packet

First, a typical response packet attached FIG:

 Structure is divided into three sections: a status line, the first line portion, and an entity body

First on the entity body may be some small partners do not understand, in fact, he is the request object itself (that is, pages).

Then look at the request packet corresponding to the request header status line position structure: status code version + + phrase (i.e. state information in response to a status code)

 

Header line:

Date: send date information in response to that message. It is retrieved from the server's file system to the object, into the response packet, and sends the response packets.

Server: User-Agent similar request packet, showing services and servers.

Last-Modified: object creation or last modification date and time. It is very important for the cache object exists on the local or proxy server.

Content-Length: the number of bytes transmitted object.

Content Type: Object type entity body. It is worth saying that the entity body content Content Type format should be specified, rather than an extension.

 

FIG response packet structure;

 

Some common status codes and associated phrases:

200 OK: the request is successful, the message returned in.

301 Moved Permanently: Requested object has been permanently transferred, the new URL is defined in the response packet Location: header line. The client software automatically get the new URL.

400 Bad Request: a generic error code indicating that the request can not be understood by the server.

404 Not Found: not on the document server being requested.

505 HTTP Version Not Support: server does not support the request message using the HTTP protocol version.

 


 

 

Guess you like

Origin www.cnblogs.com/nkcat/p/11932930.html