使用 HttpWatch 分析 HTTP 协议一例
首先下载破解版的 HttpWatch ,安装之后。按照手册中的说明,从IE中启动 HttpWatch ,点击 Record 按钮开始记录,然后在IE中输入 www.chinaunix.net 回车。我们就可以看到HTTP的实际运行的情况。
1. Overview 选项卡 (给出了基本情况)
- Overview
- URL: http://www.chinaunix.net/
- Result: 200
- ====================================================================================
- Action Decription
- ====================================================================================
- Display URL Normal browser lookup of URL http://www.chinaunix.net/ Completed
- Started At 2012-Feb-14 10:08:08.781 (local time) Completed
- DNS Lookup Lookup of hostname 'www.chinaunix.net' Completed
- Connect Connect to IP address '219.148.35.60' Completed
- HTTP Request Unconditional request sent for http://www.chinaunix.net/ Completed
- HTTP Response Headers and content returned Completed
2. TimeChart 选项卡 (给出了HTTP各个阶段所用的时间)
- Time Chart
- ====================================================================================
- Timing Started Duration
- ====================================================================================
- Blocked + 0.000 0.003
- DNS Lookup + 0.003 0.026
- Connect + 0.029 0.003
- Send + 0.032 < 0.001
- Wait + 0.032 0.087
- Receive + 0.119 0.002
- TTFB + 0.003 0.116
- 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请求头和响应头)
- Headers
- ====================================================================================
- Headers Sent Value
- ====================================================================================
- (Request-Line) GET / HTTP/1.1
- 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, */*
- Accept-Encoding gzip, deflate
- Accept-Language zh-cn
- Connection Keep-Alive
- Cookie __utma=22*****93.133*****.1329*****6.1329*****.132*****6.1;
- __utmz=225***893.132*****6.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=
- (none); Hm_lvt_0e*****1bfd76e83216b=13*****86359;
- __pta=1*****65.1*****177.13*****3293.*****389.4;
- 3comdo=132*****4820
- Host www.chinaunix.net
- User-Agent Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0;
- .NET4.0C; .NET4.0E)
- ====================================================================================
- Headers Sent Value
- ====================================================================================(Status-Line) HTTP/1.1 200 OK
- Connection close
- Content-Length 959
- 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)
- Cookies
- =========================================================================================
- CookieName Direction Value Path Domain Expires Source HTTP Only Secure
- =========================================================================================
- __pta Sent *** / .chinaunix.net Thu,**:28 GMT Stored No No
- __utma Sent *** / .chinaunix.net T***6:26 GMT Stored No No
- __utmz Sent *** / .chinaunix.net T***6:26 GMT Stored No No
- 3comdo Sent *** / .chinaunix.net T**:55 GMT Stored No No
- Hm**** Sent *** / .chinaunix.net W***1:36:26 GMT Stored No No
5. Cache 选项卡 (浏览器缓存的各种参数)
- Cache
- ====================================================================================
- Decription Before Request After Request
- ====================================================================================
- URL in cache? Yes Yes
- Expires (Not set) (Not set)
- Last Modification (Not set) (Not set)
- Last Cache Update 01:36:26 Tue***12 GMT 02:08:10 Tues***12 GMT
- Last Access 01:36:24 T***2 GMT 02:08***4, 2012 GMT
- ETag
- 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 选项卡(浏览器传给服务器的数据流,以及服务器返回给浏览器的数据流)
- Stream
- 750 bytes sent to 219.148.35.60:80
- ====================================================================================
- GET / HTTP/1.1
- 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, */*
- Accept-Language: zh-cn
- User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET4.0C; .NET4.0E)
- Accept-Encoding: gzip, deflate
- Host: www.chinaunix.net
- Connection: Keep-Alive
- Cookie: __utma=***; __utmz=22***)u***e); Hm_lv***b=1***; __pta=157***9.4; 3comdo=****0
- ====================================================================================
- 1043 bytes received by 127.0.0.1:2011
- HTTP/1.1 200 OK
Content-Length: 959
Connection: close
Content-Type: text/html
使用HtttpWatch可以方便地得到各种HTTP运行的信息,上面仅仅是摘录了一小部分来加以分析。
从上面的分析可以清楚的看到HTTP协议运行的各种情况,可以使我们加深对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