Http Study Notes (1)

Source: Internet
Author: User
Tags gmt 5
Document directory
  • Packets
Preface:

I want to write a series of articles for the first time. After learning some web knowledge, I find that I still have many shortcomings, but I don't know what to learn to improve my knowledge system, I accidentally saw an article about http on the Internet and thought it was helpful to myself. So I wanted to learn about http. I was worried that I could not stick to it, so I hope that I can urge myself to learn in this way.

 

 

Http Overview

HyperText Transfer Protocol (Hyper Text Transfer Protocol) is a Transfer Protocol used to Transfer HyperText from a WWW server to a local browser. It makes the browser more efficient and reduces network transmission. It not only ensures that the computer transfers hypertext documents correctly and quickly, but also determines which part of the transmitted documents and which part of the content is first displayed (such as text before graphics.

-- Baidu encyclopedia

First of all, http is a reliable data transmission protocol because it must be reliable. If http is unreliable, the transmitted data is always lost, if you want to read a piece of news online, only the first and third sections are displayed, which is not a crash. For reliability, I will introduce it later ., Even if the data comes from a very distant place, it can still be completely transmitted without being lost.

 

Http is stateless, that is, each request is independent and has nothing to do with the previous request. The advantage is that the server responds quickly, but it is difficult to maintain the user's status. Currently, cookies and sessions are usually used to maintain the user's status when surfing the Internet. We will discuss this issue in future notes.

Web Server

Next, let's talk about web. When talking about http, you must talk about web, because the most widely used http protocol is web. The Web server uses the http protocol. Therefore, the web server is also called an http server. in RedHat, apache uses the name httpd in the service. They provide content for the client during http transmission, so that we can see the wonderful content.

 

 

Packets

 

Every day, we use chrome and other browsers to send http requests to the web server, and then the server returns an http response message to us. The above process is called a transaction, which is a complete response process consisting of an http request command and an http response command.

This explanation may not be intuitive enough. We can use the telnet tool (for telnet linux users, you can install it through yum or apt-get, and win users can add the telnet function in the control panel) let's see what http looks like.

Assume that the IP address of a web server is 192.168.170.171 and port 80 is the default port. I tried to access it via telnet.

1 telnet> open 192.168.170.171 802 Trying 192.168.170.171...3 Connected to 192.168.170.171.4 Escape character is '^]'.5 Get /index.html HTTP/1.16 Host: 192.168.170.1717 Accept: *

In the above information, GET is a simple http request from the beginning to the end.

After sending the http message, I immediately received the following response:

 1 HTTP/1.1 200 OK 2 Date: Thu, 13 Jun 2013 07:14:43 GMT 3 Server: Apache/2.2.15 (CentOS) 4 Last-Modified: Thu, 13 Jun 2013 07:06:06 GMT 5 ETag: "c01c3-3f-4df03c3a2d5c3" 6 Accept-Ranges: bytes 7 Content-Length: 63 8 Connection: close 9 Content-Type: text/html; charset=UTF-810 

The http response information is in front of the Html Tag.

This is a simple http transaction.

They look a little scary. What exactly is there?

 

Now let's see what information is in the request.

1 GET /index.html HTTP/1.12 Host: 192.168.170.1713 Accept: *

First, GET/index.html HTTP/1.1

This statement defines that the client sends an index.html page through the GET method, and uses http1.1 protocol during transmission.

The second sentence defines the address of the target host. Of course, if there is a dns server, it is also possible to write the domain name address here.

The third sentence describes the type of MINE that the client expects to accept, that is, what type of resources the client wants. * In this example, accept any type.

 

 

Next, let's look at the response information.

 1 HTTP/1.1 200 OK 2 Date: Thu, 13 Jun 2013 07:14:43 GMT 3 Server: Apache/2.2.15 (CentOS) 4 Last-Modified: Thu, 13 Jun 2013 07:06:06 GMT 5 ETag: "c01c3-3f-4df03c3a2d5c3" 6 Accept-Ranges: bytes 7 Content-Length: 63 8 Connection: close 9 Content-Type: text/html; charset=UTF-810 

HTTP/1.1 200 OK indicates that the server uses http1.1 to transmit the response message, and status code 200 indicates that the response is successful. OK is shown to the Administrator, indicating that the response is successful.

In the second sentence, Date: Thu, 13 Jun 2013 07:14:43 GMT shows the response time.

The third sentence provides some information about the server.

In the fourth sentence, Last-Modified: Thu, 13 Jun 2013 07:06:06 GMT, And the Last modification time of the page is given.

In the fifth sentence, ETag: "c01c3-3f-4df03c3a2d5c3" is equivalent to a version number, which is related to the web cache mechanism.

The sixth Accept-Ranges: bytes indicates the range type that the server can Accept for this page resource.

Content-Length: 63 indicates the Length of the page.

Connection: close indicates that the Connection is closed.

The ninth sentence Content-Type: text/html; charset = UTF-8 here represents the text format, and character encoding of the page.

 

So far, I have a rough understanding of http transactions, and some of the above information may not be clear for the time being. I will gradually improve it later. This is today. Rest!

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.