We in the interface testing process, may use the HTTP protocol, WebService protocol, of course, with more or HTTP protocol, WebService protocol does not do too much here, we first understand the HTTP protocol, and then focus on the HTTP request and response.
HTTP protocol
Hypertext Transfer Protocol (Http,hypertext Transfer Protocol) is one of the most widely used network protocols on the Internet. All WWW documents must comply with this standard. HTTP was originally designed to provide a way to publish and receive HTML pages. 1960 American Ted Nelson conceived a way to process text messages through a computer called hypertext (hypertext), which has become the foundation of the HTTP Hypertext Transfer Protocol Standard architecture. The Ted Nelson organization coordinated the World Wide Web Association (Wide) and the Internet Engineering Working Group (Internet Engineering Task Force) to work together to study and eventually release a series of RFCs, of which the famous RFC 2616 defines the HTTP 1.1.
HTTP request
- Request Line
- Headers (Request header)
- Body (Request data)
1. Request Line
Request lines are divided into three parts: Request method, request address, and protocol version
Request Method
There are 8 types of request methods defined by http/1.1: GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS, TRACE.
The two most common get and post, if a restful interface, usually use GET, post, DELETE, PUT.
Request Address
URL: Uniform Resource Locator, is a voluntary location of the abstract unique recognition method.
Compose:< protocol >://< host >:< port >/< path >
Ports and paths can sometimes be omitted (HTTP default port number is 80)
Protocol version
The format of the protocol version is: http/major version number. Minor version number, commonly used with http/1.0 and http/1.1
2, Headerss
Common request headers are as follows:
There is a blank line at the end of the request header, which indicates the end of the request header, and then the request data, which is important and necessary.
3. Body
Get requests generally do not have a body. Post requests will be available.
HTTP Request Instance
HTTP Response
1, status line
Consists of 3 parts, namely: protocol version, Status code, status code description.
Where the protocol version is consistent with the request message, the status code description is a simple description of the status code, so this is just the status code.
Status Code
The status code is a 3-digit number.
1XX: Indicates that the request has been received and continues processing.
2XX: Success-Indicates that the request has been successfully received, understood, accepted.
3XX: Redirect--further action is required to complete the request.
4XX: Client Error--the request has a syntax error or the request is not implemented.
5XX: Server-side error-the server failed to implement a legitimate request.
Here are a few common examples:
2, headers
Common response headers are as follows:
3. Body
Not all responses have a body, and a response with a status code (such as 201 or 204) usually does not have a body
HTTP Response Instance
2. HTTP request and HTTP response