开发者

What exactly happens when you instruct your browser to go to a webpage?

I have some knowledge on my question but not exactly. What exactly programatically happening after http开发者_Go百科 request?

Scott Hanselman said in one of his blog posts:

Describe, in as much detail as you think is relevant, as deeply as you can, what happens when I type "cnn.com" into a browser and press "Go".

My question is exactly this,


That's like asking "describe how to perform a coronary bypass". Yes, one can explain how, but one is better first studying medicine and learning about the basics, before starting with specific procedures. However, in bulletpoints:

  1. Your browser will want to know the IP address of cnn.com. It doesn't do DNS lookups itself, but rather asks the operating system.
  2. Your browser will connect to that IP address on port 80
  3. Your browser will send a HTTP GET request
  4. The webserver will reply with statuscode 200 and the body contents
  5. Your browser will parse the HTML
  6. In the HTML, other resources (images, scripts, css-files...) might be included, which the browser will also fetch.
  7. After the browser is done, it will close the connection. If it doesn't, the webserver will.


Browser tries to resolve the name cnn.com into its ip address.

Browser TCP connects to cnn.com's ip address on the default HTTP port (80)

Browser sends a GET request to the server, asking for the / page

Browser says that it's trying to connect to "cnn.com" (cnn.com and bbc.com could be hosted on the same hosting company, with the same IP address)

Browser also says what's your browser, browser engine, browser version, operating system and the plug-ins that you have installed.

Server sends a header saying what's coming on your reply, the kind of data you're going to receive (in this case, HTML), and the size of the response if it's available.

Server closes the connection if there isn't any keep-alive instruction from the browser. Otherwise it will use this opened connection to ask for other things that might be needed (images within the page, for example.)

By the way, download and install Wireshark if you want to go deep and see what's really going on behind the curtains.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜