<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://www.jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://www.jackxiang.com/post//</link>
<title><![CDATA[[实践OK]利用telnet观察http协议的通讯过程--特别是telnet与http的telnet理解。]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Thu, 09 Jan 2014 02:34:40 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	背景：常常很多人对http协议不是很清楚，都干了很多年了，这块早期原始的BBS什么的都是输入命令看帖子，开发后台程序必须掌握http协议。<br/><textarea name="code" class="C" rows="15" cols="100">
[root@test ~]# telnet
telnet&gt; open w.xiyou.cntv.cn 80
Trying 127.0.0.1...
Connected to m.xiyou.cntv.cn (127.0.0.1).
Escape character is &#039;^]&#039;.
GET /HTTP/1.1
&lt;style type=&quot;text/css&quot;&gt;
#ko_error &#123; background: #ddd; font-size: 1em; font-family:sans-serif; text-align: left; color: #111; &#125;
</textarea><br/>备注：输入“GET / HTTP/1.1”，表示向该域名索要首页根文件，使用的协议是HTTP的1.1版本。<br/>当然也可更直接这样telnet：<br/><textarea name="code" class="C" rows="15" cols="100">
[root@test ~]# telnet w.xiyou.cntv.cn 80
Trying 127.0.0.1...
Connected to m.xiyou.cntv.cn (127.0.0.1).
Escape character is &#039;^]&#039;.
GET /HTTP/1.1
&lt;style type=&quot;text/css&quot;&gt;
#ko_error &#123; background: #ddd; font-size: 1em; font-family:sans-serif; text-align: left; color: #111; &#125;
</textarea><br/><br/>—————————发送telnet的注意事宜如下——————————<br/>HTTP 概述<br/>*************************************************<br/><br/>HTTP是一个客户端和服务器端请求和应答的标准（TCP）。客户端是终端用户，服务器端是网站。通过使用Web浏览器、网络爬虫或者其它的工具，客户端发起一个到服务器上指定端口（默认端口为80）的HTTP请求。（我们称这个客户端）叫用户代理（user agent）。应答的服务器上存储着（一些）资源，比如HTML文件和图像。（我们称）这个应答服务器为源服务器（origin server）。在用户代理和源服务器中间可能存在http和其他几种网络协议<br/>[1]多个中间层，比如代理，网关，或者隧道（tunnels）。尽管TCP/IP协议是互联网上最流行的应用，HTTP协议并没有规定必须使用它和（基于）它支持的层。 事实上，HTTP可以在任何其他互联网协议上，或者在其他网络上实现。HTTP只假定（其下层协议提供）可靠的传输，任何能够提供这种保证的协议都可以被其使用。 　　通常，由HTTP客户端发起一个请求，建立一个到服务器指定端口（默认是80端口）的TCP连接。HTTP服务器则在那个端口监听客户端发送过来的请求。一旦收到请求，服务器（向客户端）发回一个状态行，比如&quot;HTTP/1.1 200 OK&quot;，和（响应的）消息，消息的消息体可能是请求的文件、错误消息、或者其它一些信息。HTTP协议的网页<br/>HTTP使用TCP而不是UDP的原因在于（打开）一个网页必须传送很多数据，而TCP协议提供传输控制，按顺序组织数据，和错误纠正。 　　通过HTTP或者HTTPS协议请求的资源由统一资源标示符（Uniform Resource Identifiers）（或者，更准确一些，URLs）来标识。<br/><br/>*****************************************************<br/><br/>HTTP 与 TCP<br/><br/>HTTP是应用层协议，TCP是传输层协议<br/>数据包在网络传输过程中，HTTP被封装在TCP包内<br/>所以建立HTTP连接时，首先要TCP三次握手。<br/><br/><br/>利用telnet可以与服务器建立http连接，获取网页，实现浏览器的功能。<br/>它对于需要对http header进行观察和测试到时候非常方便。因为浏览器看不到http header。<br/><br/>步骤如下：<br/><br/>1. 运行/cmd<br/>2. telnet www.baidu.com 80<br/>3. 组合键“Ctrl + ]”打开回显，回车。<br/>4. 输入GET /index.html HTTP/1.1 并2次回车。<br/><br/>这时就应该可以看到http response了，包括了header和body。<br/><br/>/*因为window自己带到telnet在输入内容的时候看不到输入的内容，可以下载putty并选用raw tcp connection的方式进行连接。<br/>效果一样，但是毕竟方便好用。*/<br/><br/>需要注意到事情如下：<br/>1. GET 和 HTTP必须大写，因为很多服务器要求大写，小写的话在一些服务器会造成连接失败。<br/><br/>2. HTTP1.1的话，还需要加上一行写明host, 这是http1.1的要求。<br/>GET /officers.html HTTP/1.1<br/>host: www.csua.berkeley.ed<br/><br/>3. 2次回车表示把request发出去，因为http request是以最后一行为空行来表示结束的。<br/><br/>4. 一些比较聪明的网站会屏蔽掉不是浏览器的http request， 这时我们就需要假扮浏览器，需要set的User-agent。<br/>GET /officers.html HTTP/1.1<br/>host: www.csua.berkeley.ed<br/>User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5<br/><br/>4.1 连接一次即断开<br/>connection:close&nbsp;&nbsp;Http1.1 默认链接为长连接状态keep-alive，若要更改为链接一次即断开<br/>在请求中加入以上状态。<br/><br/>5. 抓取http连接的package可以使用Wireshark，获取浏览器的http request和response，再用telnet模拟浏览器进行连接<br/><br/>上述来自：http://wenku.baidu.com/view/fe0f351fff00bed5b9f31ddc.html###<br/>上面谈到伪装浏览器，有curl更方便。<br/><br/>参考:http://wenku.baidu.com/view/42dc2b18fad6195f312ba62a.html<br/><br/>实验目的及原理：<br/>&nbsp;&nbsp;&nbsp;&nbsp;利用MS的telnet工具，通过手动输入http请求信息的方式，向服务器发出请求，服务器接收、解释和接受请求后，会返回一个响应，该响应会在telnet窗口上显示出来，从而从感性上加深对http协议的通讯过程的认识。<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;实验步骤：<br/><br/>1、打开telnet<br/>1.1 打开telnet<br/>运行--&gt;cmd--&gt;telnet<br/><br/>1.2 打开telnet回显功能<br/>set localecho<br/><br/>2、连接服务器并发送请求<br/>2.1 open www.guet.edu.cn 80&nbsp;&nbsp;//注意端口号不能省略<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;HEAD /index.asp HTTP/1.0<br/>&nbsp;&nbsp;&nbsp;&nbsp;Host:www.guet.edu.cn<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp; /*我们可以变换请求方法,请求桂林电子主页内容,输入消息如下*/<br/>&nbsp;&nbsp;&nbsp;&nbsp;open www.guet.edu.cn 80 <br/>&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;GET /index.asp HTTP/1.0&nbsp;&nbsp;//请求资源的内容<br/>&nbsp;&nbsp;&nbsp;&nbsp;Host:www.guet.edu.cn&nbsp;&nbsp;<br/><br/>2.2 open www.sina.com.cn 80&nbsp;&nbsp;//在命令提示符号下直接输入telnet www.sina.com.cn 80<br/>&nbsp;&nbsp;&nbsp;&nbsp;HEAD /index.asp HTTP/1.0<br/>&nbsp;&nbsp;&nbsp;&nbsp;Host:www.sina.com.cn<br/> <br/><br/>3 实验结果：<br/><br/>3.1 请求信息2.1得到的响应是:<br/><br/>HTTP/1.1 200 OK&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//请求成功<br/>Server: Microsoft-IIS/5.0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//web服务器<br/>Date: Thu,08 Mar 200707:17:51 GMT<br/>Connection: Keep-Alive&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>Content-Length: 23330<br/>Content-Type: text/html<br/>Expries: Thu,08 Mar 2007 07:16:51 GMT<br/>Set-Cookie: ASPSESSIONIDQAQBQQQB=BEJCDGKADEDJKLKKAJEOIMMH; path=/<br/>Cache-control: private<br/><br/>//资源内容省略<br/><br/>3.2 请求信息2.2得到的响应是:<br/><br/>HTTP/1.0 404 Not Found&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //请求失败<br/>Date: Thu, 08 Mar 2007 07:50:50 GMT<br/>Server: Apache/2.0.54 &lt;Unix&gt;<br/>Last-Modified: Thu, 30 Nov 2006 11:35:41 GMT<br/>ETag: &quot;6277a-415-e7c76980&quot;<br/>Accept-Ranges: bytes<br/>X-Powered-By: mod_xlayout_jh/0.0.1vhs.markII.remix<br/>Vary: Accept-Encoding<br/>Content-Type: text/html<br/>X-Cache: MISS from zjm152-78.sina.com.cn<br/>Via: 1.0 zjm152-78.sina.com.cn:80&lt;squid/2.6.STABLES-20061207&gt;<br/>X-Cache: MISS from th-143.sina.com.cn<br/>Connection: close<br/><br/><br/>失去了跟主机的连接<br/><br/>按任意键继续...<br/><br/>4 .注意事项：1、出现输入错误，则请求不会成功。<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2、报头域不分大小写。<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3、更深一步了解HTTP协议，可以查看RFC2616，在http://www.letf.org/rfc上找到该文件。<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4、开发后台程序必须掌握http协议<br/><br/>摘自：http://www.cnblogs.com/li0803/archive/2008/11/03/1324746.html<br/><br/><br/><br/>——————————————————————telnet与http——————————————————————<br/>在cmd命令下输入<br/><br/><br/>telnet localhost 8080 回车<br/><br/>//先写好下面两行，再粘贴到命令行上，粘贴在上面的内容是看不见的，两次回车后就有结果了。<br/><br/>POST /test/login.jsp HTTP/1.1<br/><br/>Host:localhost 回车 回车（两次回车得到结果）<br/><br/>结果如下：（以下是自己写的jsp页面，在这里通过post方法显示得到）<br/>HTTP/1.1 200 OK<br/>Server: Apache-Coyote/1.1<br/>Set-Cookie: JSESSIONID=00CFCBA663892EC713FD9BDB7A02BA32; Path=/test/; HttpOnly<br/>Content-Type: text/html;charset=UTF-8<br/>Content-Length: 867<br/>Date: Wed, 18 Apr 2012 14:07:54 GMT<br/><br/><br/><br/><br/>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;&gt;<br/>&lt;html&gt;<br/>&nbsp;&nbsp;&lt;head&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;base href=&quot;http://localhost:80/test/&quot;&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;My JSP &#039;login.jsp&#039; starting page&lt;/title&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;meta http-equiv=&quot;pragma&quot; content=&quot;no-cache&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;meta http-equiv=&quot;cache-control&quot; content=&quot;no-cache&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;meta http-equiv=&quot;expires&quot; content=&quot;0&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;meta http-equiv=&quot;keywords&quot; content=&quot;keyword1,keyword2,keyword3&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;meta http-equiv=&quot;description&quot; content=&quot;This is my page&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;styles.css&quot;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--&gt;<br/><br/>&nbsp;&nbsp;&lt;/head&gt;<br/><br/>&nbsp;&nbsp;&lt;body&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;form action=&quot;Login&quot; method=&quot;post&quot;&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;username:&lt;input type=&quot;username&quot; name=&quot;username&quot;&gt;&lt;br&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;password:&lt;input type=&quot;password&quot; name=&quot;password&quot;&gt;&lt;br&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type=&quot;submit&quot; value=&quot;submit&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type=&quot;reset&quot; value=&quot;reset&quot;&gt;&lt;br&gt;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/form&gt;<br/><br/><br/>&nbsp;&nbsp;&lt;/body&gt;<br/>&lt;/html&gt;<br/><br/><br/>********************************************************************************************************************************<br/>//Login为web.xml中url-pattern中的值<br/>telnet localhost 8080 回车<br/>GET /test/Login HTTP/1.1<br/>Host:localhost 回车 回车<br/><br/>（结果省略。。。）<br/><br/><br/>telnet www.sina.com.cn 回车<br/>GET /index.html HTTP/1.1<br/>Host:www.sina.com.cn&nbsp;&nbsp; 回车 回车<br/><br/>（结果省略。。。）<br/><br/><br/>HEAD /index.html HTTP/1.1 回车<br/>Host:www.sina.com.cn&nbsp;&nbsp;回车 回车（两次回车得到结果）<br/><br/>（结果省略。。。）<br/><br/>以上来自：http://blog.csdn.net/zklxuankai/article/details/7475427
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] [实践OK]利用telnet观察http协议的通讯过程--特别是telnet与http的telnet理解。]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>