Browser Access Web Site

1. Connect When we enter such a request, we must first establish a socket connection, because the socket is established by ip and port, so there is a DNS resolution before the process, become the http://www.baidu.com/ ip, if the url is not included in the port number will default port number for the protocol to use.
DNS process is this: First, we know that we will fill in the DNS on the local machine when configuring the network, so that the machine will send this to the url configured DNS server, if it can find the url ip returns, otherwise, the DNS will continue to send the resolution request to the DNS higher, can be seen as a DNS entire tree structure, the request is sent up to the root until the results. Now has a target ip and port number, so that we can open a socket connection.
2. After a successful connection request, starts sending a request to a web server, this request is typically GET or POST command (POST transfer parameters for FORM). GET command format is: GET path / filename HTTP / 1.0
filename indicates that the file being accessed, HTTP / 1.0 Web browser pointed HTTP version used. Can now send the GET command:
GET /mytest/index.html the HTTP / 1.0,
3. web server receives the request response, the processing. It's a document from the search space in a subdirectory of the file index.html mytest. If the file is found, Web server sends the file content to the appropriate Web browser.
To tell the browser ,, Web server first transmits a number of HTTP headers, and then transmits the specific content (i.e. HTTP-information), separated by a blank line between the information and the HTTP body of the HTTP header information.
Common HTTP headers have:
  ① the OK HTTP 1.0 200 This is the first line of a Web server response, HTTP version number is listed and the response code server is running. The code "200 OK" indicates that the request is complete.
  ② MIME_Version: 1.0 It indicates the MIME type version.
  ③ content_type: This type of information is important header that indicates the MIME type of the HTTP message body. Such as: content_type: Data text / html indication is transmitted HTML document.
  ④ content_length: length value that indicates the length of the HTTP message body (bytes).

4. Close the connection: When answering the end, Web browser and the Web server must be turned off to ensure that other Web browsers can connect to the Web server.

Guess you like

Origin blog.51cto.com/14375779/2415963