HTTP request response process differs from HTTPS

Source: Internet
Author: User
Tags file transfer protocol apache tomcat

Original: HTTP request response process and HTTPS differences

HTTP Protocol Learning notes, basics, dry goods HTTP protocol

The main application of the HTTP protocol is between the server and the client, and the client accepts hypertext.

The server sends the communication protocol to the client (typically the browser) in accordance with certain rules. Similar to the File Transfer Protocol (file transfer protocol,ftp), the Simple Mail Transfer Protocol (single-mail ttransfer protocol,smtp) and so on.

HTTP is the protocol for the application layer in the seven-tier network model, which consists of sending requests and accepting responses, and is a standard client server model . At the same time, HTTP is a stateless protocol . In other words, the state of the connection cannot be judged by a state, so sometimes communication between computers needs to work together through other protocols to provide support.

The working characteristics of the HTTP protocol

http has its own characteristics relative to other network transport protocols, which also supports the basic functions of the HTTP protocol.

(1) based on b/S mode, i.e. client / server mode . At the same time can provide login authentication and inter-network security transfer, such as HTTP under the SSL layer, can provide a secure HTTPS service .

(2) small communication overhead, simple and fast, low transmission cost . When the server requests certain services, the browser usually simply adds the request path and method in the request message. The most common situations, such as Get,HEAD,POST , and so on, are the most commonly used.

Each request method has its own scope of application, in the request message inside, through some rules, explain the user and the Web server type of communication. At the same time,HTTP protocol rules are relatively simple, so the system using HTTP server , code and program size is relatively lightweight, but the speed of communication is more efficient .

(3) Flexible: Hypertext protocol allows servers and clients to transfer data objects of any type or arbitrary data structure . Also, a simple header message, such as marking the type being transmitted by Content-type , can be separated.

(4) Save transfer Time : The initial version of the HTTP protocol uses a non-persistent connection, allowing only one connection to be sent and processed , when the request response is complete, that is, the server completes the client's request, The connection is immediately disconnected after receiving a response from the client browser . With this feature, the communication method saves a lot of time for data transmission and waiting for response, and the time cost becomes very small.

At the same time, HTTP 1.1 supports persistent connections in the high-version HTTP protocol: Multiple objects can be routed through a single connection, creating a new connection without having to transfer one Web object at a time.

(5) can affect transmission efficiency, stateless : TheHTTP protocol is a stateless protocol. stateless, if the protocol has no memory mechanism for transaction processing, cannot store processing progress, at this time, if the subsequent operation requires the previous processing information, it is necessary to resend the object must be re-transmitted, the consequence is that there may be multiple connections to complete the operation, the amount of data will become larger.

how the HTTP protocol works

Typically, the HTTP protocol works well to understand that the user initiates a request to the server through the client, creates a TCP connection , specifies the port number, and Defaults to , and then connect to the server to work. Listen for browser requests on that port. Once the client request is heard, the server returns a response status to the client, such as "http/1 ," after parsing the request type. 0 404 OK" also returns specific data content, such as requested resource, error code, other status information, and so on.

Message format for HTTP protocolRequest message for HTTP protocol

When the browser sends a request to the server to the Web servers , it sends a block of data, or requests information ,

The HTTP request information consists of 3 parts:

Request method URI Protocol/version;

The request header (ask header);

Request body;

The following is an example of an HTTP request :

get/test.jsp Http/1.1accept:image/test.image/jpeg,*/*accept-language:zh-cnconnection:keep-alivehost : 222.35.232.103user-agent:mozila/5.0 (compatible; MSIE5.01; Window NT5.0) Accept-encoding:gzip,deflateusername=bingyue&password=bingyue

  

(1) Request method URI Protocol / version

The first line of the request is " method / content URL Protocol / protocol version name":

get/test.jsp http/1.1

In the above code, "GET" describes the request method,"/test.jsp" represents network resources, intermediate spaces, and finally describes the Protocol and protocol versions.

UnderHTTPStandard,HTTPRequestYou can use a variety of different request methods. For example:HTTP1.1Allows seven request methods to be supported (also called"Action"):GET,POST,HEAD,OPTIONS,PUT,DELETEand theTarce. In daily development, GETand thePOSTIs the most commonly used method, mainly in the relevantWebin Development。

The URL path Specifies the network resource to be accessed. In general, we need a relative path, because the location of the resource is determined, the path of the network resource relative to the root of the server is available, so the "/" begins . At the end of the header information, the version of the HTTP protocol version used during the communication process is declared.

It is important to note that the method name is strictly case-sensitive. Sometimes, the resource that a request is targeted for may not support the corresponding request method, and the response is given by a different status code. For example , the server will return a status code 405 ( method not allowed ) when the requesting server or method does not understand that the corresponding time is not supported. Returns a status code 501 ( not implemented ).

(2) requesting header ( request header)

The request header contains some customer environments and requested content information. For example , the request header can declare the browser kernel and language usage , The requested length, and so on .

Accept:image/test.image/jpeg.*/*accept-language:zh-cnconnection:keep-alivehost:222.35.232.103user-agent:mozila /5.0 (compatible:msie5.01:windows NT5.0) accept-encoding:gzip,deflate.

(3) Request Body

The request body and the request header should have a blank line. This empty line must be present, stating the end of the request header transfer and beginning the transfer of the body request. The request body generally contains a lot of information, such as user-submitted user name and password such as login information: Userlogin=bingyue&currentpwd=bingyue

In real-world applications, the request body of the protocol can contain a large amount of information , rather than an example of HTTP , please

, the request body has only a simple row of data.

Response messages for HTTP protocols

Similar to the request message, the HTTP response is mainly composed of 3 parts:

(1) Protocol status version Code description

(2) Response Head (Response header)

(3) Response body

The following is an example of an HTTP response :

http/1.1 Okserver:apache tomcat/7.0.1date:mon,6oct2014 13:23:42 gmtcontent-length:102

The client sends a request to the server, similar to a request message, and the server responds with a status line.

Response messages include:version of the HTTP protocol, result encoding, and other necessary information, such as entity information . Response categories are different, and the response message can contain or have no entity content.

HTTP response messages begin with the status line, which can refer to the code of the example.

The response head, which is the message header, is the same as the header of the request, which contains important information, such as datetime and server type, and content length and quantity.

A more detailed description:

What is the process of a complete HTTP transaction?

Application of Status code in HTTP protocol

HTTP request response process differs from HTTPS

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.