Http

HTTP message format

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 the request parameters in the HTTP request data in the form of name/value, which can transmit a large amount of data and can be used to transmit files.
(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 header informs the server about the client's request. Typical request headers are:
User-Agent: The type of browser that generated 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, send carriage return and line feed to notify the server that there are no more request headers below.
A blank line is necessary for a complete http request, otherwise the server will think that the data of this request has not been completely sent to the server and is in a waiting state.
(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.
(5) Request example
POST:
The POST header is as follows:

POST /sn/index.php HTTP/1.1
Accept: */*
Accept-Language: zh-cn
host: localhost


Content-Type: application/x-www-form-urlencoded
Content-Length: 12
Connection:close
sn=123&n=asa
There is a blank line after the http header, and post data is sent after the blank line, and the length is
indicated by Content-Length: 12 , this post data contains two items
sn=123
n=asa
Among them: Content-Type: application/x-www-form-urlencoded Specifies the encoding type of POST data
Content-Length: 12 Length of POST data




GET:
GET header As follows:
GET /sn/index.php?sn=123&n=asa HTTP/1.1
Accept: */*
Accept-Language: zh-cn
host: localhost


Content-Type: application/x-www-form-urlencoded
Content-Length: 12
Connection:close

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324838622&siteId=291194637