从输入网址到浏览器显示页面的详细过程

本文详细介绍了从用户在浏览器中输入URL到最终呈现网页内容的全过程。涵盖了浏览器如何查找域名对应的IP地址、发送HTTP请求、处理服务器响应及重定向、解析并渲染HTML文件等多个关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

从输入网址到浏览器显示页面的详细过程:

  1. browser checks cache; if requested object is in cache and is fresh, skip to #9

  2. browser asks OS for server's IP address

  3. OS makes a DNS lookup and replies the IP address to the browser

  4. browser opens a TCP connection to server (this step is much more complex with HTTPS)

  5. browser sends the HTTP request through TCP connection

  6. browser receives HTTP response and may close the TCP connection, or reuse it for another request

  7. browser checks if the response is a redirect (3xx result status codes), authorization request (401), error (4xx and 5xx), etc.; these are handled differently from normal responses (2xx)

  8. if cacheable, response is stored in cache

  9. browser decodes response (e.g. if it's gzipped)

  10. browser determines what to do with response (e.g. is it a HTML page, is it an image, is it a sound clip?)

  11. browser renders response, or offers a download dialog for unrecognized types

来源:http://stackoverflow.com/questions/2092527/what-happens-when-you-type-in-a-url-in-browser

下面是一些比较详尽的解释:

英文: http://igoro.com/archive/what-really-happens-when-you-navigate-to-a-url/

中文:http://www.cnblogs.com/wenanry/archive/2010/02/25/1673368.html

1、在浏览器中输入地址,按下回车键

2、浏览器查找域名的IP地址,dns按照先后顺序查找ip地址

  1.                 浏览器缓存:浏览器会缓存DNS记录一段时间,不同浏览器会储存不同的固定的一个时间

  2.                 系统缓存:如果在浏览器缓存里没有找到需要的记录,浏览器会做一个系统调用,获得系统缓存中的记录

  3.                 路由器缓存

  4.                 ISP DNS 缓存 

  5.                 递归搜索:ISP的DNS服务器从跟域名服务器开始进行递归搜索

3、浏览器给web服务器发送一个HTTP请求

HTTP客户机在端口80发起一个到服务器的TCP连接(三次握手),客户机通过建立的HTTP连接创建的套接字向服务器发送HTTP请求

GET http://facebook.com/ HTTP/1.1

 Accept: application/x-ms-application, image/jpeg, application/xaml+xml, [...]

 User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; [...]

 Accept-Encoding: gzip, deflate

 Connection: Keep-Alive

 Host: facebook.com

 Cookie: datr=1265876274-[...]; locale=en_US; lsd=WW[...]; c_user=2101[...]

GET 这个请求定义了要读取的URL: “http://facebook.com/”。 浏览器自身定义 (User-Agent 头), 和它希望接受什么类型的相应 (Accept and Accept-Encoding 头). Connection头要求服务器为了后边的请求不要关闭TCP连接。请求中也包含浏览器存储的该域名的cookies。可能你已经知道,在不同页面请求当中,cookies是与跟踪一个网站状态相匹配的键值。这样cookies会存储登录用户名,服务器分配的密码和一些用户设置等。Cookies会以文本文档形式存储在客户机里,每次请求时发送给服务器。

4. facebook服务的永久重定向响应

HTTP服务器进程通过与请求连接相关的套接字接受请求报文,从存储器检索出对象,在一个HTTP响应报文中封装对象,并通过连接套接字向客户机发送响应报文。

HTTP/1.1 301 Moved Permanently

 Cache-Control: private, no-store, no-cache, must-revalidate, post-check=0,

 pre-check=0

 Expires: Sat, 01 Jan 2000 00:00:00 GMT

 Location: http://www.facebook.com/

 P3P: CP="DSP LAW"

 Pragma: no-cache

 Set-Cookie: made_write_conn=deleted; expires=Thu, 12-Feb-2009 05:09:50 GMT;

 path=/; domain=.facebook.com; httponly

 Content-Type: text/html; charset=utf-8

 X-Cnection: close

 Date: Fri, 12 Feb 2010 05:09:51 GMT

 Content-Length: 0

服务器给浏览器响应一个301永久重定向响应,这样浏览器就会访问“http://www.facebook.com/” 而非“http://facebook.com/”

5. 浏览器跟踪重定向地址


6. 服务器“处理”请求


7. 服务器发回一个HTML响应


8. 浏览器开始显示HTML


9. 浏览器发送获取嵌入在HTML中的对象


10. 浏览器发送异步(AJAX)请求


转载于:https://my.oschina.net/hnuweiwei/blog/222141

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值