使用 HttpWatch 分析 HTTP 协议

本文通过使用 HttpWatch 分析工具,详细介绍了 HTTP 协议的各个方面,包括 Overview、TimeChart 中的各项时间指标,以及如何理解 TTFB、DNS Lookup 和 Connect 等关键步骤。内容还涉及了浏览器缓存、HTTP 请求头信息和数据流等内容,帮助读者深入理解 HTTP 协议的工作原理。
摘要由CSDN通过智能技术生成


使用 HttpWatch 分析 HTTP 协议一例


首先下载破解版的 HttpWatch ,安装之后。按照手册中的说明,从IE中启动 HttpWatch ,点击 Record 按钮开始记录,然后在IE中输入 www.chinaunix.net 回车。我们就可以看到HTTP的实际运行的情况。

1. Overview 选项卡 (给出了基本情况)

  1. Overview
  2. URL:           http://www.chinaunix.net/
  3. Result:        200
  4. ====================================================================================
  5. Action         Decription
  6. ====================================================================================
  7. Display URL    Normal browser lookup of URL http://www.chinaunix.net/    Completed
  8. Started At     2012-Feb-14 10:08:08.781 (local time)                     Completed
  9. DNS Lookup     Lookup of hostname 'www.chinaunix.net'                    Completed
  10. Connect        Connect to IP address '219.148.35.60'                     Completed
  11. HTTP Request   Unconditional request sent for http://www.chinaunix.net/  Completed
  12. HTTP Response  Headers and content returned                              Completed

2. TimeChart 选项卡 (给出了HTTP各个阶段所用的时间)

  1. Time Chart
  2. ====================================================================================
  3. Timing         Started    Duration
  4. ====================================================================================
  5. Blocked        + 0.000    0.003
  6. DNS Lookup     + 0.003    0.026
  7. Connect        + 0.029    0.003
  8. Send           + 0.032    < 0.001
  9. Wait           + 0.032    0.087
  10. Receive        + 0.119    0.002
  11. TTFB           + 0.003    0.116
  12. Network        + 0.003    0.118

1)The Blocked time includes any pre-processing time(such as cache lookup) and the time spent waiting for a network connection to become available. Internet Explorer will only create a maximum of two concurrent network connections per host name (i.e. www.microsoft.com) and will queue up requests until a network connection is available. Often the Blocked time is the most significant factor in the download time of images embedded in a web page.

阻塞时间括所有的过程之前的时间(像,cache对比)和等待网络链接的时间,IE在每个主机名(像www.microsoft.com)下最多只创建两个当前的网络连接,而且要排队等待直到这个网络链接可用,通常,闭塞时间影响网页中图片加载时间的重要因素。

2)DNS Lookup is the time required to resolve a host name (e.g. www.google.com) into a numeric IP address (e.g. 216.239.59.99).

域名解析:针对于DNS的解析只做一次解析

3)Connect is the time required to create a TCP connection to the web server (or proxy). If a secure HTTPS connection is being used this time includes the SSL handshake process. Keep-Alive connections are often used to avoid the overhead of repeatedly connecting to the web server.

连接时间:是创建TCP连接到服务器或者代理服务器所花费的时间,如果一个包含SSL的安全的HTTPS连接存在,Keep-Alive链接经常被用到,以避免多次重复的连接WEB服务器。

4)Send is the time required to send the HTTP request message to the server and will depend on the amount of data that is sent to the server. For example, long Send times will result from uploading files using an HTTP POST

发送时间:是发送HTTP请求到服务器的时间,而且这个时间取决与发送请求的数据量的大小,例如,长的发送时间是由于用PSOT方式上传文件造成的。

5)Wait is the idle time spent waiting for a response message from the server. This value includes delays introduced due to network latency and the time required to process the request on the web server.

等待时间:是花费在等待服务器响应消息的空闲时间,这个值包括网络延迟和服务器处理请求的时间。

6)Receive is the time taken to read the response message from the server. This value will depend on the size of the content returned, network bandwidth and whether HTTP compression was used.

接收时间:是花费在从服务器读取响应消息的时间。这个值可以受到请求消息内容的大小,网络带宽和是否使用了HTTP压缩

7)TTFB (or Time To First Byte) is the duration from the initial network request being initiated by the browser to the first byte being received from the server. It includes TCP connection time, the time to send the request and the time taken to get the first byte of the response message.

TTFB(Tome To First Byte)是最初的网络请求被发起到从服务器接收到第一个字节这段时间,它包含了TCP连接时间,发送HTTP请求时间和获得响应消息第一个字节的时间。

8)Network is the total duration of all network related operations for an HTTP request.

Network:是所有的对一个HTTP请求的相关操作的这段时间。


3. Headers 选项卡 (HTTP请求头和响应头)
  1. Headers
  2. ====================================================================================
  3. Headers Sent      Value
  4. ====================================================================================
  5. (Request-Line)    GET / HTTP/1.1
  6. Accept            application/x-shockwave-flash, image/gif, image/jpeg, image/pjpeg, 
  7.                   image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint,
  8.                   application/msword, application/xaml+xml, application/x-ms-xbap, 
  9.                   application/x-ms-application, */*
  10. Accept-Encoding   gzip, deflate
  11. Accept-Language   zh-cn
  12. Connection        Keep-Alive
  13. Cookie            __utma=22*****93.133*****.1329*****6.1329*****.132*****6.1; 
  14.                   __utmz=225***893.132*****6.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=
  15.                   (none); Hm_lvt_0e*****1bfd76e83216b=13*****86359; 
  16.                   __pta=1*****65.1*****177.13*****3293.*****389.4; 
  17.                   3comdo=132*****4820
  18. Host              www.chinaunix.net
  19. User-Agent        Mozilla/4.(compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0;
  20.                   .NET4.0C; .NET4.0E)
  21. ====================================================================================
  22. Headers Sent      Value
  23. ====================================================================================(Status-Line)    HTTP/1.1 200 OK
  24. Connection        close
  25. Content-Length    959
  26. Content-Type      text/html
们从上面可以看到:
1)浏览器要求使用长连接Connection Keep-Alive),但是服务器使用的是短连接Connection close).
2)请求头的基本格式:
首先是请求行,其格式是:Action(get或者post或者...) + 资源的路径(/)+ HTTP协议的版本(HTTP/1.1)
接下来是“请求头”,即浏览器的各种参数:
Accept表示浏览器可以接受的资源类型;
Accept-Encoding表示浏览器的可以接收的压缩格式类型;
Accept-Language表示浏览器使用的语言;
Cookie是浏览器传输给服务器的cookie信息;
然后是一个 \r\n 用来分隔“请求头”和请求内容
最后是请求的内容。

3)响应头的基本格式:
首先是响应状态行,其格式是:协议(HTTP/1.1)+  状态信息(200 OK);
接下来是“响应头”,就是服务器响应的各种参数;
然后是一个 \r\n 用来分隔“响应头”和请求内容;
最后是请求的内容。

4. Cookie 选项卡 (浏览器传给服务器的cookie)

  1. Cookies
  2. =========================================================================================
  3. CookieName Direction Value Path  Domain        Expires         Source  HTTP Only Secure
  4. =========================================================================================
  5. __pta      Sent       ***   /   .chinaunix.net  Thu,**:28 GMT   Stored    No       No
  6. __utma     Sent       ***   /    .chinaunix.net T***6:26 GMT    Stored    No       No
  7. __utmz     Sent       ***   /    .chinaunix.net T***6:26 GMT    Stored    No       No
  8. 3comdo     Sent       ***   /    .chinaunix.net T**:55 GMT      Stored    No       No
  9. Hm****     Sent       ***   /    .chinaunix.net W***1:36:26 GMT Stored    No       No

5. Cache 选项卡 (浏览器缓存的各种参数)

  1. Cache
  2. ====================================================================================
  3. Decription           Before Request              After Request 
  4. ====================================================================================
  5. URL in cache?        Yes                            Yes
  6. Expires              (Not set)                    (Not set)
  7. Last Modification    (Not set)                    (Not set)
  8. Last Cache Update    01:36:26 Tue***12 GMT        02:08:10 Tues***12 GMT
  9. Last Access          01:36:24 T***2 GMT           02:08***4, 2012 GMT
  10. ETag        
  11. Hit Count            7                             9

其中我们看到,本次访问 http://www.chinaunix.net 利用浏览器缓存中的内容,并没有重新全部从服务器得到所有的内容。
Hit Count 的表示的是“击中了缓存的次数”
6. Query String 选项卡 (表示通过get方法传给服务器的参数,比如 id=23433&name=dkdkkd等等内容)
由于我们访问的是http://www.chinaunix.net所以没有Query String。注意通过数据库注入就是通过Query String来构造各种到数据库查询,从而从返回的结果分析从而得到各种关于数据库的信息的。
7. Stream 选项卡(浏览器传给服务器的数据流,以及服务器返回给浏览器的数据流)

  1. Stream
  2. 750 bytes sent to 219.148.35.60:80
  3. ====================================================================================
  4. GET / HTTP/1.1
  5. Accept: application/x-shockwave-flash, image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/xaml+xml, application/x-ms-xbap, application/x-ms-application, */*
  6. Accept-Language: zh-cn
  7. User-Agent: Mozilla/4.(compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET4.0C; .NET4.0E)
  8. Accept-Encoding: gzip, deflate
  9. Host: www.chinaunix.net
  10. Connection: Keep-Alive
  11. Cookie: __utma=***; __utmz=22***)u***e); Hm_lv***b=1***; __pta=157***9.4; 3comdo=****0
  12. ====================================================================================
  13. 1043 bytes received by 127.0.0.1:2011
  14. HTTP/1.1 200 OK
    Content-Length: 959
    Connection: close
    Content-Type: text/html  













使用HtttpWatch可以方便地得到各种HTTP运行的信息,上面仅仅是摘录了一小部分来加以分析。

从上面的分析可以清楚的看到HTTP协议运行的各种情况,可以使我们加深对HTTP协议的理解。


在iteye.com上有几篇分析HTTP的博文:
http://yzd.iteye.com/blog/1405107  HTTP协议详解,你所不知到的
http://javababy1.iteye.com/blog/1404091  HTTP协议和web本质
http://javasee.iteye.com/blog/1405109 Fiddler宝典

此文参考:http://blog.chinaunix.net/uid-25909722-id-3072233.html


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值