用telnet发送HTTP请求进行测试

时间:2023-01-20 15:16:58

 用telnet发送HTTP请求进行测试

    在日常工作中可能经常发送HTTP请求对服务器进行测试,如果用专门的工具显得不方便,也比较耗时间。而telnet则是比较方便的工具之一。

第一步: telnet到目标机的端口:如

telnet www.baidu.com 80

 

如果目标机正常,则会出现如下的情况:

[root ~]# telnet www.baidu.com 80
Trying 202.108.22.43...
Connected to www.baidu.com (202.108.22.43).
Escape character is '^]'.

 

 

此时输入

GET / HTTP/1.1
Host: www.baidu.com
再加两个回车,如果一切正常,系统会返回如下。

[root ~]# telnet www.baidu.com 80
Trying 202.108.22.43...
Connected to www.baidu.com (202.108.22.43).
Escape character is '^]'.
GET / HTTP/1.1
Host: www.baidu.com

HTTP/1.1 200 OK
Date: Mon, 09 Nov 2009 07:50:56 GMT
Server: BWS/1.0
Content-Length: 3520
Content-Type: text/html;charset=gb2312
Cache-Control: private
Expires: Mon, 09 Nov 2009 07:50:56 GMT
Set-Cookie: BAIDUID=CE207C279A7C9F5A3B05535EBC8E81F0:FG=1; expires=Mon, 09-Nov-39 07:50:56 GMT; path=/; domain=.baidu.com
P3P: CP=" OTI DSP COR IVA OUR IND COM "

<html><head><meta http-equiv=Content-Type content="text/html;charset=gb2312"><title>°Ù¶Èһϣ¬Äã¾ÍÖªµÀ      </title><style>body{margin:4px 0}p{margin:0;padding:0}img{border:0}td,p,#u{font-size:12px}#b,#u,#l td,a{font-family:arial}#kw{font:16px Verdana;height:1.78em;padding-top:2px}#b{height:30px;padding-top:4px}#b,#b a{color:#77c}#u{padding-right:10px;line-height:19px;text-align:right;margin:0 0 3px !important;margin:0 0 10px}#sb{height:2em;width:5.6em}#km{height:50px}#l{margin:0 0 5px 15px}#l td{padding-left:107px}p,table{width:650px;border:0}#l td,#sb,#km{font-size:14px}#l a,#l b{margin-right:1.14em}a{color:#00c}a:active{color:#f60}#hp{position:absolute;margin-left:6px}#lg{margin:-26px 0 -44px}#lk{width:auto;line-height:18px;vertical-align:top}form{position:relative;z-index:9}</style></head>
<body><div id=u><a href=http://passport.baidu.com/?login&tpl=mn>µÇ¼</a></div><center><img src=http://www.baidu.com/img/baidu_logo.gif width=270 height=129 usemap="#mp" id=lg><br><br><br><br><table cellpadding=0 cellspacing=0 id=l><tr><td><div id=m><a onclick=s(this) href=http://news.baidu.com>ÐÂ&nbsp;ÎÅ</a><b>Íø&nbsp;Ò³</b><a onclick=s(this) href=http://tieba.baidu.com>Ìù&nbsp;°É</a><a onclick=s(this) href=http://zhidao.baidu.com>Öª&nbsp;µÀ</a><a onclick=s(this) href=http://mp3.baidu.com>MP3</a><a onclick=s(this) href=http://image.baidu.com>ͼ&nbsp;Ƭ</a><a onclick=s(this) href=http://video.baidu.com>ÊÓ&nbsp;Ƶ</a></div></td></tr></table>
<table cellpadding=0 cellspacing=0 style="margin-left:15px"><tr valign=top><td style="height:62px;padding-left:92px" nowrap><form name=f action=s><input type=text name=wd id=kw size=42 maxlength=100> <input type=submit value=°Ù¶ÈһϠid=sb><span id=hp><a href=/gaoji/preferences.html>ÉèÖÃ</a><br><a href=/gaoji/advanced.html>¸ß¼¶</a></span></form></td></tr></table>
<p id=km><a href=http://hi.baidu.com>¿Õ¼ä</a>&nbsp;&nbsp;<a href=http://www.hao123.com>hao123</a>&nbsp;|&nbsp;<a href=/more/>¸ü¶à<span style="font-family:ËÎÌå">>></span></a></p>
<p style=height:60px><table cellpadding=0 cellspacing=0 id=lk><tr><td></td></tr></table></p>
<p style=height:30px><a onClick="this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.baidu.com')" href=http://utility.baidu.com/traf/click.php?id=215&url=http://www.baidu.com>°Ñ°Ù¶ÈÉèΪÖ÷Ò³</a></p><p style=height:14px><a href=http://e.baidu.com>¼ÓÈë°Ù¶ÈÍƹã</a> | <a href=http://top.baidu.com>ËÑË÷·çÔÆ°ñ</a> | <a href=http://home.baidu.com>¹ØÓÚ°Ù¶È</a> | <a href=http://ir.baidu.com>About Baidu</a></p><p id=b>&copy;2009 Baidu <a href=http://www.baidu.com/duty/>ʹÓðٶÈÇ°±Ø¶Á</a> <a href=http://www.miibeian.gov.cn target=_blank>¾©ICPÖ¤030173ºÅ</a> <img src=http://gimg.baidu.com/img/gs.gif></p><map name=mp><area shape=rect coords="43,22,227,91" href=http://hi.baidu.com/baidu/ target=_blank title="µã´Ë½øÈë °Ù¶È¿Õ¼ä"></map></center></body>
<script>var w=document.f.wd;function s(o){if(w.value.length>0){var h=o.href;var q=encodeURIComponent(w.value);if(h.indexOf("q=")!=-1){o.href=h.replace(new RegExp("q=[^&$]*"),"q="+q)}else{o.href+="?q="+q}}};(function(){if(new RegExp("q=([^&]+)").test(location.search)){w.value=decodeURIComponent(RegExp.$1)}})();if(navigator.cookieEnabled&&!/sug?=0/.test(document.cookie)){document.write('<script src=http://www.baidu.com/js/bdsug.js?v=1.1.0.3><//script>')};if(window.attachEvent){window.attachEvent("onload",function(){w.focus();})}else{window.addEventListener('load',function(){w.focus()},true)};window.onunload=function(){};</script></html><!--0e94a8fd6438cdd2-->

Connection closed by foreign host.