"HTTP request", detailed

Source: Internet
Author: User
Tags apache tomcat

I. Introduction of the Agreement

HTTP (Hypertext Transfer Protocol, Hypertext Transfer Protocol) is a set of computers to communicate through the network rules, so that the HTTP client can request from the HTTP server to the information and services, the current version number is 1.1 is a stateless protocol, Stateless means sending an HTTP request from the client to the server, which responds after the server receives the request, so that the link is closed and the client's information is not required on the server side.

Ii. The process of agreement

HTTP communication mechanism is a complete HTTP communication process, the client and the server to establish a connection between the following steps.

1. Establish the connection: including: Domain name resolution, TCP three handshake.

Domain Name resolution: Convert the Domain name in the HTTP request to an IP address, where the main steps are, in chrome, for example, to access the www.baidu.com

① first, Chrome will search the browser's own DNS cache (less cache), see if it has changed the IP address of the domain name, if there is a stop resolution return IP, if not continue parsing.

Note: DNS in chrome can view the browser's DNS cache by entering the chrome://net-internals/#dns in the browser.

② if it is not found in the browser's own DNS cache, chrome searches the operating system's own DNS cache and stops if it finds it, and no further parsing is found.

Note: You can view the DNS cache for the operating system from the command line Ipconfig/displaydns.

      

③ If Chrome is not found in the DNS cache of the operating system, it tries to read the host (C:\WINDOWS\SYSTEM32\DRIVERS\ETC) file to see if there is a corresponding DNS address in it

    

④ if it is not found in the host file, then chrome sends a DNS system call that first sends the domain name resolution to the default DNS server (which is typically the network operator by default, sends a request to DNS port 53 via the UDP protocol), and if the network operator has the domain cache, Then return IP, if not, the carrier's DNS will initiate an iterative DNS resolution request, first find the root domain IP address, that is, the IP address of the COM domain. The operator will continue to want the COM domain to send the domain name resolution request, obtains the IP address of the baidu.com domain, obtains the IP address which needs to resolve the domain name (if www.baidu.com is so difficult to access, then the retired is not far away).

TCP Three-time handshake: After you get the IP of the domain name, the client sends a TCP link request to the Web server with a random port (80 ports default, and sometimes 8080 ports).

    

    

2. Send data:

After the client establishes a connection with the server, the client sends a packet to the server where the packet contains the following information

⑴ Request Method URI Protocol/version

⑵ Requests Header (request header)

⑶ Request Body

eg.

    

Get/index.jsphttp/1.1accept:image/gif.image/jpeg,*/*accept-language:zh-cnconnection:keep-alivehost: localhostuser-agent:mozila/4.0 (compatible; MSIE5.01; Window NT5.0) accept-encoding:gzip,deflate username=jinqiao&password=1234

⑴ Request Method URI Protocol/version

The first line of the request get/index.jsp http/1.1

"GET" represents the request method, "/index.jsp" represents the URI protocol, "http/1.1" represents the Protocol and protocol version, where HTTP1.1 supports seven methods, Get,post,head,put,delete,trace,connect, OPTIONS. The following is mainly about the get and post methods.

GET: The default HTTP request data, simply encode the information that needs to be submitted, and append the information to the URL address after eg. Http://localhost/login.php?username=aa&password=1234 this creates the risk of exposing the user's information. and the browser will limit the length of the URL, so the information submitted is also limited.

Post: The primary role is to submit form information to the web, overcoming the disadvantage of get insecurity and data length limitations, and post does not append data to the URL after the data is sent, and is safe relative to the Get method (using the Post method is recommended).

⑵ Request Header

After the second line of the request is the request header, which contains information about the client environment, including: Browser language, request body length and so on.

⑶ Request Body

There is a blank line after the request header ends (a blank line indicates that the request header ends and the request body starts)

3. Return Data:

After the server receives a client-side request, it starts responding to the client side and returns the packet. Where the packet contains the following information

⑴ Protocol Status Version Code description

⑵ response Header

⑶ Response Body

eg.

    

1 http/1.1 OK2 Server:apache tomcat/5.0.123 date:mon,6oct2003 13:23:42 GMT4 content-length:1125  6 <HTML>7 <Head>8 ...9 </Body>Ten </HTML>

⑴ Protocol Status Version Code description

The first line of the response, "http/1.1", is the protocol version, and a $ OK indicates a successful response

HTTP answer code is also a status code, reflecting the status of this HTTP request, which is divided into the following several

1XX-Information class, indicating receipt of request for further processing

2XX-A successful class that indicates that the user's request was correctly received, understood, processed. For example, OK

3XX-redirect class to indicate that the user request is unsuccessful and the client needs to take further action

4XX-Client error, which indicates a client request error, where 404 Not fount indicates that the resource was not found

5XX-server-side error, indicating that the server could not complete a relative error, typically a server internal error.

⑵ response Header

Similar to the request

⑶ Response Body

A blank line after the end of the response header indicates that the response header ends and the response body begins.

4. Close the connection:

The connection is disconnected via a TCP four-time handshake.

  

HTTP request, detailed

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.