1. Initiating an HTTP request
1.1 HTTP requests from the browser
It is easy to initiate an HTTP request. For example, you want to use a browser to access Reddit. All you need to do is enter http://www.reddit.com in the browser's address bar and you can see it. The server hosting the Reddit handles your request and gives you a response, and your browser is smart enough to show the picture, text, and style to your eyes.
1.2 Sending HTTP requests using the HTTP tool
Because browsers show us what the browser has done, we don't see the true nature of the files sent to us by the browser. So how do you see the raw data that the server responds to us?
For this we can use a tool chrome plugin for DHC by Restlet, and we can see the following response information:
This is a lot worse than what we see in the browser, and if you haven't seen the original data for the HTTP response before, you'll be amazed at how he did it. In fact, the data you see now is the data that the browser receives, but the browser has done some human-friendly processing of the data in the browser.
If you learn the HTTP protocol just to be a web developer, you will have to learn the original HTTP response data, but you don't have to interpret it as a picture in your mind, but you should have a holistic view of what these responses represent, and when you have enough experience, you can go deep into the original HTTP response data to do some debugging work and find out what it is.
1.3 Using the Moderator (inspector)
All browsers have a way to view HTTP requests and responses, often called censors. We use the chrome viewer, which we use to analyze your browser's HTTP communication.
1 Open the Chrome browser, click on the menu in the top right corner, more tools, developer tools.
2 Enter http://www.reddit.com in the Address bar and return to Reddit to resend a new request.
More than 3 keep the moderator open, then click the Network tab.
4 The first thing you should be aware of is that there will be many items here. Each item is a separate request, that is, simply by accessing the URL, your browser initiates multiple requests, and a request corresponds to a resource (picture, file, and so on). Click on the first request to the homepage, which is the one www.reddit.com
5 This contains the request header, the response header information.
6 in the default headers, there is the request header information sent to the server and the corresponding response header information of the server. Click the Response tab to display the original data for the response.
This corresponds to the same data that you see in the HTTP tool.
Another thing to note is that when we use the moderator, there is a bunch of other requests coming back under the Network tab, in addition to the first request:
Why do these additional responses occur, and who initiated these requests? The thing is, when we ask for a resource, the initial request for it www.reddit.com
returns some HTML. These HTML also refer to other resources than slices, CSS files, JavaScript files and so on. Your browser, very smart and very strong. It understands that in order to show a Web page that can be viewed, it has to take the resources that are quoted as well. As a result, the browser initiates a request for one by one of each resource in the resulting initial response. When you scroll down the page in the Network tab, you can see all the relevant resources. These other requests guarantee that this web page and other things can be displayed properly on your screen. Overall, the browser's moderator gives you a good experience with reference resources. On the other hand, a purely HTTP tool will only return a huge response to the data, The referenced resource is not automatically pulled.
HTTP protocol Learning Notes