www.jianshu.com/p/8fe93a147…

Request

  1. Request line Request line
  2. Request Header Header
  3. A blank line
  4. Request body

Packet capture request structure:

GET /mix/76.html? Name =kelvin&password=123456 HTTP/1.1 Host: www.fishbay.cn upgrade-insecure -Requests: 1 user-agent: Mozilla / 5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml; Q = 0.9, image/webp, * / *; Q =0.8 Accept-encoding: gzip, deflate, SDCH Accept-language: zh-cn,zh; Q = 0.8, en. Q = 0.6Copy the code

1. The request

GET is the request type, /mix/76.html? Name = Kelvin&Password =123456 indicates the resource to be accessed. HTTP/1.1 indicates the protocol version

2. Request headers

From the second line in the request header, Host indicates the destination of the request (Host domain name); User-agent is client-side information that is important to detect the browser type, defined by the browser, and sent automatically with each request.

3. A blank line

The request header must be followed by an empty line

4. The request body

The requested data, also called the request body, can be added to any other data. The request body for this example is empty.

Response

  1. Status line Request line
  2. The response headers
  3. A blank line
  4. Response body

Packet capture response structure:

HTTP/1.1 200 OK Server: nginx Date: Mon, 20 Feb 2017 09:13:59 GMT Content-Type: text/plain; HTTP/1.1 200 OK Server: nginx Date: Mon, 20 Feb 2017 09:13:59 GMT Content-type: text/plain; charset=UTF-8 Vary: Accept-Encoding Cache-Control: no-store Pragrma: no-cache Expires: Thu, 01 Jan 1970 00:00:00 GMT Cache-Control: no-cache Content-Encoding: gzip Transfer-Encoding: chunked Proxy-Connection: Keep-alive {"code":200,"notice":0,"follow":0,"forward":0,"msg":0,"comment":0,"pushMsg":null,"friend":{"snsCount":0,"count":0,"celeb rityCount":0},"lastPrivateMsg":null,"event":0,"newProgramCount":0,"createDJRadioCount":0,"newTheme":true}Copy the code

1. The status line

The status line consists of the protocol version number, status code, and status message

2. The response headers

The response header is information that the client can use, such as Date (the Date on which the response was generated), Content-Type (MIME Type and encoding format), Connection (long Connection by default), and so on

3. A blank line

The request header must be followed by an empty line

4. The response body

The requested data, also called the request body, can be added to any other data. The request body for this example is empty.

Status code

The HTTP status code consists of three digits. The first digit defines the category of the response. There are five categories:

  1. 1xx: Indicating message – indicates that the request has been received and processing continues
  2. 2xx: Success: The request is successfully received, understood, and accepted
  3. 3xx: Redirect – Further action must be taken to complete the request
  4. 4xx: client error – The request has a syntax error or the request cannot be implemented
  5. 5xx: server side error – The server failed to fulfill a valid request

Common status codes:

401 Unauthorized // The Request is Unauthorized. This status code must be used with the www-Authenticate header field using 403 Forbidden // The server received the request but refused to provide the service 404 Not Found // The requested resource did Not exist, eg: An incorrect URL is entered. 500 Internal Server Error // An unexpected Error occurs on the Server. 503 Server Unavailable // The Server cannot process requests from the clientCopy the code