Detailed interface testing basics

HTTP URL (URL is a special type of URI, contains a resource for finding enough information) in the following format:
HTTP: // Host [ ":" Port] [abs_path ]
HTTP pledged to come through the HTTP protocol locating network resources; host have a legal Internet host domain name or IP address; port specify a port number is empty then the default port 80; abs_path specified request URI of the resource; if the URL is not given abs_path, then when it as a request when URI, must be given to "/" form, usually the job browser automatically help us to complete.
EG:
. 1, Input: www.guet.edu.cn
browser automatically converted to: http://www.guet.edu.cn/
2, HTTP: 192.168.0.116: 8080 / the index.jsp 

http request consists of three parts, namely: a request line, header message, request body

1, the method begins with a request line symbol, separated by spaces, URI, and the protocol followed by the requested version, the following format: Method Request-URI HTTP-Version CRLF
wherein represents Method request method; Request-URI is a Uniform Resource Identifier ; HTTP-version represents the HTTP protocol version request; CRLF represents carriage return and linefeed (CRLF as the end of the addition, does not allow a separate character CR or LF).

GET method: When you enter the URL of the way the browser address bar to access the web browser using GET method to get resources to the server, eg: GET /form.html HTTP / 1.1 (CRLF)

POST method requires the server to accept the requested data back attached to the request, to submit the form used.
eg: POST /reg.jsp HTTP / (CRLF )

 

Three, HTTP protocol detailed response to the article

    After receiving and interpreting a request message, the server returns a HTTP response message.

HTTP response is composed of three parts, namely: a status line, the message header, the response body
1, the status line in the following format:
HTTP-Version the Status-Code Reason-Phrase CRLF
wherein, HTTP-Version indicates a version of the server HTTP protocol; Status -Code represents the server sends back the response status code; Reason-Phrase represent text description of the status code.
Status code has three numbers, the first number in response to the defined categories, and there are five possible values:
1xx: indication information - indicates a request has been received, processing continues
2xx: Success - indicates that the request has been successfully received, understood, accepted
3xx: redirection - to fulfill the request must go a step further
4xx: client error - the request has a syntax error or a request can not be achieved
5xx: server-side error - the server failed to achieve a legitimate request
common status code, state description, explanation :
200 the OK // client request was successful
400 Bad request // client requests a syntax error, can not be understood by the server
401 unauthorized // request is not authorized, the status code must be used with the WWW-Authenticate header field
403 Forbidden / / server receives the request, but refused to provide service
404 not Found // requested resource does not exist, eg: enter the wrong the URL of
500 Internal server error // server goes unexpected errors
503 server unavailable // server is currently unable to process client request may return to normal after a period of time
eg:HTTP/1.1 200 OK (CRLF)

 

Request header
request header to allow the client to the server with the requested information additional information about itself and the client.
Common request header
the Accept
the Accept request header field is used to specify what type of information the client accepted. eg: Accept: image / gif, indicates that the client wishes to receive resources GIF image format; Accept: text / html, indicates that the client wishes to accept html text.
The Charset-the Accept
the Accept the Charset request-header field is used to specify the character sets accepted by the client. eg: Accept-Charset:. iso -8859-1, gb2312 If this field is not set in the request message, the default character set can be any acceptable.
-Encoding the Accept
the Accept-Encoding request header field is similar to Accept, but it is acceptable for specifying content encoding. eg: Accept-Encoding:. gzip.deflate If the request is not set this field to the message server assumes that the client for encoding various contents are acceptable.
Language-the Accept
the Accept-Language request header field similar to Accept, but it is used to specify a natural language. eg: Accept-Language:. zh -cn If the request is not set in the message header field, the server assumes that the client can accept a variety of languages.
The Authorization
the Authorization request header field is mainly used to prove the client has permission to view a resource. When a browser to access a page, if the server receives a response code of 401 (unauthorized), may send a request Authorization request header field contains, it requires the server to be verified.
Host (transmission request, the header field is required)
Host request header field is mainly used to specify the requested resource Internet host and port number, which is usually extracted from the HTTP URL, eg:
we enter in the browser: http://www.guet.edu.cn/index .html
request message sent by the browser, will contain Host request header field, as follows:
Host: www.guet.edu.cn
used herein default port number 80, if a port number is specified, then becomes: Host: www.guet.edu.cn : specify the port number
User-Agent
we landed Internet forums, you often will see some welcome message, which lists the name and version of your operating system, the name of the browser you are using and versions, which often makes a lot of people feel very magical, in fact, is to get the server application from the User-Agent header field to the request information. User-Agent request header field allows the client to its operating system, browser, and other attribute tells the server. However, the header field is not required, if you write a browser ourselves, do not use User-Agent request header field, then the server will not know our message.

When the WWW-Authenticate response header field must be included in 401 (unauthorized) response message, the client receives the 401 response message, when, and transmits Authorization header field requests the server to be verified, the server response header contains header area.
eg: WWW-Authenticate: Basic realm = "! Basic Auth Test" // server can be seen on the requested resource uses basic authentication mechanism.

 

The entity header
request and response messages may be transmitted one entity. An entity by the entity header field, and entity body composition, but does not mean that the entity header fields and entities to send the text to be together, you can send only entity header field. Entity headers defined on the entity body: meta-information resources (eg whether the entity body) and request identified.
Common entity header of
the Content-Encoding
the Content-Encoding entity header field is used as a media type modifiers, and a value indicating the coding has been applied to the entity body of the additional content, thus to obtain the referenced Content-Type header field media type, the corresponding decoding mechanism must be used. Content-Encoding compression method for recording such a document, EG: Content-Encoding: gzip
Content-Language
Content-Language entity header field describes the natural language resources used. This field is not set is considered an entity content will be available to all languages read
by. EG: the Content-Language: DA
the Content-the Length
the Content-entity the Length header field for indicating the length of the entity body of the decimal number is stored in bytes to represent.
The Type-the Content
the Content-term the Type header field indicates the entity to a recipient entity body of the media type. EG:
the Content-the Type: text / HTML; charset = the ISO-8859-1
the Content-the Type: text / HTML; charset = GB2312
Last-Modified
Last-Modified entity header field for the last modified date and time indication of resources.
Expires
Expires entity header field gives the date and time response expired. In order for a proxy server or browser updates the cache after a period of time (when accessing the page was visited again, loaded directly from the cache, faster response times and reduce server load) of the page, we can use Expires entity header fields specified page time expired. EG: the Expires: Thu, 15 Sep 2006 16:23:12 GMT
HTTP1.1 the client and the cache must be other illegal date format (including zero) considered to have expired. eg: In order for the browser not to cache pages, we can also use Expires entity header fields, set to 0, jsp program as follows: response.setDateHeader ( "Expires", " 0");

Guess you like

Origin www.cnblogs.com/georgexu/p/11224081.html