HTTP protocol [Detailed] - classic interview questions (rpm)

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

HTTP (Hypertext Transfer Protocol) is a request response mode based, stateless application layer protocol, usually based on the TCP connection, the HTTP1.1 release mechanism is given continuously connected, most Web development, Web applications are built on top of the HTTP protocol.

1, common HTTP methods are there? GET: request for access has been resource URI (uniform resource identifier) identified, can pass parameters to the server through a URL. POST: used to transmit information to the server, and the main function is similar to the GET method, but it is generally recommended to use the POST method. PUT: file transfer, the message body contains the contents of the file, is saved to a corresponding URI position. HEAD: get the message header with the GET method is similar, but does not return the message body, generally used to verify URI is valid. DELETE: delete the file, and the PUT method Instead, delete the file corresponding to the URI location. OPTIONS: check the appropriate HTTP method URI supports. 2, GET method differs POST method one difference: GET focus on access to resources from the server, POST focus data sent to the server; Difference between the two: GET transmit data via a URL request to the Field (Field) = value form, after the URL is placed, and connected with, among the plurality of request data "&" connected, such as http://127.0.0.1/Test/login.action?name=admin&password=admin, the process visible to the user "?"; data transmitted via the post post Http mechanism of the storage field corresponds to the value in the request sent to the server entity, this process is not visible to the user; three differences:















Get a small amount of data transferred, because by the URL length limit, but a higher efficiency;
Post can transmit large amounts of data, so the only way to upload files with Post;
distinguish four:
GET is not safe, because the URL is visible, may leak private information, such as passwords and so on;
POST higher than get security;
distinguish five:
get way can only support ASCII characters, the server transfer of Chinese characters may be garbled.
post supports standard character set, you can transfer Chinese characters correctly.


3, HTTP request packet and response packet format

The request message comprises three parts:
A, request line: comprises a request method, the URI, HTTP version information
B, the request header field
C, the requested content entity
response message comprises three parts:
A, status line: comprises HTTP version, status code, status code reason phrase
B, a response header field
C, a content entity in response to

4, the respective common HTTP status code

Returns status
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 be carried out further operations
4xx: Client error - syntax error in the request or the request can not be achieved
5xx: server-side error - the server failed to achieve a legitimate request


200: the request is processed normally
204: the request is accepted but no resource can return
206: The client only requests a portion of the resource, the server performs only partial resource request GET method, the respective packet resource Content-Range specified range through.
301: Permanent redirect
302: Temporary Redirect
303: with the 302 status code similar functions, except that it want the client request when a URI, GET method can be redirected to another URI
304: transmitting untied request, when the return condition is not satisfied, irrespective of redirection
307: temporary redirection, and 302 similar, except using the POST method mandatory
400: request message syntax error, the server does not recognize
401: request requires authentication
403: request prohibit access to the corresponding resource is
404: server was unable to find the corresponding resource
500: internal server error
503: server busy




5, HTTP1.1 version of the new features
a, a persistent connection by default to save traffic, as long as the client server has not specified at either end of the TCP connection, it is always connected, you can send multiple HTTP requests

B, pipelined, multiple clients can issue HTTP requests simultaneously, rather than in response to a wait

c, HTTP principle



6, common HTTP header fields a, common header fields (header field request packets and response packets are used) a Date: Create a message Time Connection: managing connections Cache-Control: cache control Transfer-Encoding: The message body transfer encoding mode b, the request header field (request packet will use header field) the host: request resource is a server Accept: media type can handle the character set that can be received: the Accept-the charset the Accept-encoding: acceptable content encoding Accept-language: acceptable natural language c, in response header field ( header field of a response packet will use) the Accept-Ranges: bytes acceptable range Location: make the client to redirect the URI server: HTTP server installed information d, the entity header field (header field of the request packet using a substantial portion of the response message of) the Allow: resources to support HTTP methods Content-type: entity main class type Content-encoding: the entity body of encoding to be used Content-language: Natural language entity-body Content-Length: number of bytes in the entity body of Cont ent-Range: entity-body position range, typically used for issuing a request portion
























7, a disadvantage of HTTP and HTTPS
A, unencrypted communications using clear text, the content may be tapped
b, does not verify the identity of the communicating parties, may have been disguised
c, can not verify message integrity, may be tampered

HTTPS is HTTP plus encryption processing (SSL secure communication link typically) + + integrity protection certification

8, HTTP optimization

Load balancing to optimize and accelerate HTTP application

Use HTTP Cache to optimize website

Guess you like

Origin www.cnblogs.com/wuliaojava/p/11772795.html