HTTP application Basics

Source: Internet
Author: User

HTTP is an application layer protocol for distributed, collaborative, and hypermedia information systems.

How HTTP works:

HTTP is in line with the C/S model, and requests are always initiated by the Client. The whole process can be simply divided into the following four steps:

1) The client initiates a request to 'tcp three handshakes 'with the server ';

2) the client sends an "HTTP request message" to the server ";

3) after the server completes internal processing, it sends an "HTTP response packet" to the client ";

4) the client and the server complete the "TCP four-way handshake ";

Hypertext Transfer Protocol URL:

Syntax and semantics stipulated in the URL scheme of Hypertext Transfer Protocol:

Http: // host [: port] [path]

Http: // indicates the HTTP protocol to be used;

Host: available domain name or IP address

Port: (optional) port number.

Path: (optional) indicates the path of the requested resource. The default value is/

Packet composition:

1) starting line: start line

2) Header: Header

3) Subject: body

Content obtained using the wfetch tool: (use/*... */Annotations)1) HTTP Request Message:The REQUEST line consists of three fields: Method Field, URI field, and HTTP Version field REQUEST: * ************ \ n/* this is a request to Baidu: the HTTP Version is shown as HTTP 1.1 and the method is GET, apply for resources from the server/*/GET/HTTP/1.1 \ r \ n/* Host to specify the server Host to be requested as 220.181.112.244 */Host: 220.181.112.244 \ r \ nAccept: */* \ r \ n/* here is an empty line, and it is required. This is a rigid provision of the HTTP protocol */\ r \ n2) HTTP Response Message:RESPONSE: *************** \ n/* The first line is the status line, which includes three fields: under the version field, Status field, and reason phrase field * // *, the HTTP Response expression is that the server uses HTTP 1.1 and finds the resources required by the client, the response message is sent to the client. The entire process is normal */HTTP/1.1 200 OK \ r \ n/* the time when the response message is sent */Date: Sat, 31 May 2014 07:09:12 GMT \ r \ n/* indicates the HTML text Content when the contained data */Content-Type: text/html; charset = UTF-8 \ r \ nTransfer-Encoding: chunked \ r \ nConnection: Keep-Alive \ r \ nVary: Accept-Encoding \ r \ nSet-Cookie: BAIDUID = Accept: FG = 1; expires = Thu, 31-Dec-37 23:55:55 GMT; max-age = 2147483647; path =/; domain = .baidu.com \ r \ nSet-Cookie: BDSVRTM = 15; path =/\ r \ nSet-Cookie: H_PS_PSSID = success; path =/; domain = .baidu.com \ r \ nP3P: CP ="Oti dsp cor iva our ind com "\R \ n/* Cache Control */Cache-Control: private \ r \ nExpires: Sat, 31 May 2014 07:09:12 GMT \ r \ nX-Powered-: the HPHP \ r \ n/* Server domain indicates that the response message is sent by the BWS Server and the version is 1.1 */Server: BWS/1.1 \ r \ nBDPAGETYPE: 1 \ r \ nBDQID: 0x81b75e41000579e6 \ r \ nBDUSERID: 0 \ r \ n/* The empty lines here cannot be omitted */\ r \ n/* Subject */.............

HTTP message format:

Connection:

Advantages of permanent HTTP connections:

1) Opening and Closing fewer TCP connections will save the CPU time on the vro and host, and save the memory used by the TCP control block on the host.

2) HTTP requests and responses can communicate with each other through pipelines. The pipeline allows the client to send multiple requests after each response, allowing a single TCP connection to be used more effectively and taking less time.

3) reduce network congestion, reduce the number of packets opened by TCP, and determine the network congestion status by allowing TCP to have sufficient time.

4) The latency of the Post-order request is supported because there is no time spent on the handshake between the two TCP connections.

5) HTTP can evolve better, and errors can be reported without the penalty of disabling TCP connections.

HTTP status code:

Information

100 Continue: the client should Continue its request;

101 Switching Protocols: the server understands and is willing to accept client requests;

Successful

This type of Status Code indicates that the client request is successfully received, understood, and accepted;

200 OK: the request is successful.

201 Created: the request is successful and a new resource is Created.

202 Accepted: the request has been processed, but the process has not been completed.

203 Non-Authoriative Infomation: the meta information returned in the object header is not a set effectively determined by the original server, but is collected from a local or a third party.

204 No Content: the server has completed the request;

205 Reset Content: the server has completed the request and the user agent should Reset the document view that caused the request to be sent.

206 Partial Content: the server resource has completed the GET request for a local resource;

Redirection

This type of Status Code indicates that the user agent must take further actions to complete the request.

300 Multiple Choices: the requested resource matches any one of the expression sets and each has its own special location.

301 Moved Permannently: the requested resource has been specified to a new permanent URI, and any future reference to this resource should use one of the returned Uris.

302 Found: the requested resource temporarily has different Uris.

303 See Other: the request response can be found in different Uris, And the GET method should be used to obtain it from the resource.

304 Not Modified: if the client executes the condition GET request and allows access, but the document does Not change, the server uses this response code to respond.

305 USE Proxy: the requested resource must be accessed through the Proxy provided in the Location domain.

306: reserved;

Client error:

The status code of the 4xx class is used to indicate that the client has an error.

400 Bad Request: the server cannot understand the Request due to malformed syntax. The client should not repeat the request that has not been modified.

401 unauthorized: The request requires user authentication.

402 Payment Required: reserved;

403 Forbidden: the server understands the request but rejects the request.

404 Not Found: the server cannot match anything of Request-URI;

405 Method not Allowed: The resource identified by Request-URI cannot be used for the Method specified in Request-Line.

406 Not Acceptable: the content and features of the resource identified by the request are Not accepted by the receiving header sent in the request, so a response cannot be generated;

407: similar to 401

408 Request Timeout: the client does not generate any Request during the waiting time of the server.

409 Conflict: the request is not completed because of a Conflict with the existing status of the resource;

410 Gone: the requested resource is no longer valid on the server and the forwarding address is unknown.

411 Length required: the server rejects unspecified requests;

412 Precondition Failed: Test Evaluation fails on the server on the premise given in one or more request header fields.

413: the server rejects the request because the sex entity is longer than the length that the server is willing to or can handle;

414: the server rejects the service Request because the Request-URI is longer than the length that the server is willing to parse;

415: the server rejects service requests because the request entity is in a format not supported by the resources requested by the request method;

416: the server should return the response of this status code. If the request includes the Range request header and the Range specified in this field does not overwrite the current length of any selected Xiyuan;

Server Error

The response status code with a number of 5 headers indicates that the server is obviously in an error or is unable to execute the request;

500 Internal Server Error: the Server is blocked from completing the request when unexpected conditions occur.

501 not implemented: the server does not provide the required functions;

502 Bad Gateway: when used as a Gateway or proxy, the server receives an invalid response trying to complete the request from the upstream server that it approaches.

503 Service unavailable: the server cannot process requests because of temporary overload or server maintenance;

504 Gateway Timeout: when used as a Gateway or proxy, when the server tries to complete the request, it does not receive a scheduled response from the URI specifying my upstream server or some other auxiliary servers that need to access it;

505 HTTP Version Not Supported: the HTTP protocol Version used in the request message is Not Supported by the server or rejected.

HTTP cache:

HTTP is generally used in distributed information systems, and its performance may be improved through response caching.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.