HTTP message format (transfer)

HTTP messages are text-oriented, each field in the message is some ASCII code string, and the length of each field is indeterminate. HTTP has two types of messages: request messages and response messages.

request message

An HTTP request message consists of four parts: request line, request header, blank line and request data. The following figure shows the general format of the request message.

 

 (1) Request line

The request line consists of three fields: the request method field, the URL field, and the HTTP protocol version field, which are separated by spaces. For example, GET /index.html HTTP/1.1.

The request methods of the HTTP protocol include GET, POST, HEAD, PUT, DELETE, OPTIONS, TRACE, and CONNECT. Here are the most commonly used GET and POST methods.

GET: The GET method is used when the client wants to read the document from the server. The GET method requires the server to place the resource located by the URL in the data part of the response message and send it back to the client. When using the GET method, the request parameters and corresponding values ​​are appended to the URL, and a question mark ("?") is used to represent the end of the URL and the beginning of the request parameters. The length of the passed parameters is limited. For example, /index.jsp?id=100&op=bind.

POST: The POST method can be used when the client provides more information to the server. The POST method encapsulates request parameters in HTTP request data, in the form of name/value, and can transmit large amounts of data.

(2) Request header

The request header consists of keyword/value pairs, one pair per line, and the keyword and value are separated by an English colon ":". The request headers inform the server about the client request. Typical request headers are:

User-Agent: The type of browser that made the request.

Accept: A list of content types recognized by the client.

Host: The requested host name, multiple domain names are allowed to share the same IP address, that is, a virtual host.

(3) Blank line

After the last request header is a blank line, sending a carriage return and a newline to inform the server that there are no more request headers below.

(4) Request data

Request data is not used in GET method, but in POST method. The POST method is suitable for situations where the customer is required to fill out a form. The most commonly used request headers related to request data are Content-Type and Content-Length.

 

POST请求时,我读取完/r/n后,再读取一行,发现没有可以读取的内容了,那么请求数据应该怎样读取呢?

 

2010.07.20

终于弄清楚了为什么按照上面的方法读取不了请求数据,而且还跳转不到指定的地方,这是因为请求数据并不是按行存取的,即不以'/n'结束,所以因为读取不了/n而进入了死循环状态。

 只要将缓冲区的剩余部分,用printf打印出来即可。

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326931400&siteId=291194637