发送HTTP请求的两种方式

<script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
写了两个测试了一下,自己看看吧

public void GetResponse()
        {
            StringBuilder strSource = new StringBuilder();
            try
            {
                //WebRequest Wreq = WebRequest.Create(" HTTP://www.dev-club.com");
                //WebResponse Wresp = Wreq.GetResponse();

                Uri myUri = new Uri(this.l_strPageAddress);
                 HTTPWebResponse resp;
                 HTTPWebRequest req =
                    ( HTTPWebRequest)WebRequest.Create(myUri);
                resp = ( HTTPWebResponse)req.GetResponse();


                StreamReader sr = new StreamReader(resp.GetResponseStream(),Encoding.Default);
                string strTemp = "";

                while((strTemp = sr.ReadLine()) != null)
                {
                    strSource.Append(strTemp + "/r/n");
                }

                sr.Close();
            }
            catch(WebException WebExcp)
            {
                strSource.Append(WebExcp.Message);
            }
            this.form.AddMessage(strSource.ToString());
        }

        public void Socket_GetResponse()
        {
            

                IPHostEntry ipinfo    = Dns.Resolve(l_strServerAddress);
                IPAddress ip        = ipinfo.AddressList[0];
                IPEndPoint rip        = new IPEndPoint(ip,80);    

                s = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);

                try
                {

                this.form.AddMessage("Connecting to "+ip.ToString());

                s.Connect(rip);

                int bytesRecv = 0;
                string output = "";
                string temp   = "";
                byte[] bytes;

                this.form.AddMessage("Sending request to "+l_strPageAddress);

                string Command = "post " +l_strPageAddress+" HTTP/1.0/r/n";
                Command += "Accept:*/*/r/n";
                Command += "Accept:text/html/r/n";
                Command += "/r/n";

                byte[] msg = Encoding.Default.GetBytes(Command);


                int intSend = s.Send(msg,msg.Length,0);

                this.form.AddMessage("Sent "+intSend.ToString()+" bytes to server");

                do
                {
                    bytes = new byte[1024];
                    bytesRecv = s.Receive(bytes,bytes.Length,SocketFlags.None);
                    temp = Encoding.Default.GetString(bytes,0,bytesRecv);
                    this.form.AddMessage(temp);
                    output += temp;
                }
                while (bytesRecv>0);

                this.form.AddMessage(output);
            }
            catch(Exception e)
            {
                this.form.AddMessage(e.Message);
            }
            finally
            {
                if (s != null & s.Connected)
                {
                    s.Shutdown(SocketShutdown.Both);
                    s.Close();
                }
            }

        }

下面是结果

Response from remote
Connecting to 61.135.135.13
Sending request to HTTP://dev-club.ccw.com.cn/club/bbs/bbsView.asp?essenceID=18292
Sent 111 bytes to server
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.0
Date: Tue, 19 Mar 2002 20:04:23 GMT
pragma: no-cache
cache-control: private
Connection: Keep-Alive
Content-Length: 2025
Content-Type: text/html
Expires: Mon, 18 Mar 2002 20:04:22 GMT
Set-Cookie: ASPSESSIONIDGQQQQVCK=GELPBBIBLDCMOIOEAIBHINMB; path=/
Cache-control: no-cache

<!--
    - Dev-club.com开发者俱乐部
    - Based on Active BBS 5.0 By shenpengfei@hotmail.com
    - Last Updated: 2001-12-1
-->

<html>
<head>
<meta HTTP-EQUIV="Content-Type" content="text/html; charset=gb2312">
<link REL="SHORTCUT ICON" href=" HTTP://www.chinaasp.com/icon.ico">
<link rel="stylesheet" type="text/css" href="css/style.CSS">
<title>计算机世界开发者俱乐部</title>
<style>
.navPoint
    {
    font-family: Webdings;
    font-size:9pt;
    color:black;
    cursor:hand;
    }
p{
    font-size:9pt;
}
</style>
<script language="javascript" src="js/rollover.js">
</script>
<script language="javascript">
    var bLoad=false;
    
    function doRefresh(){
        self.frames[1].location="refresh.asp
"
        setTimeout("doRefresh()",60000)
    }
    function init(){
        doRefresh()
        //MM_preloadImages('Images/head_about_on.gif','Images/head_course_on.gif','Images/head_partner_on.gif','Images/head_news_on.gif','Images/head_continue_on.gif','Images/head_job_on.gif');
    }
    window.onload = doRefresh
</script>
<script language="javascript1.1" src="js/dcookie.js"></script>
<script>
if (do
cument.all==null) window.location.href="NotIEView.asp?essenceID=18292"
function monitor(){
window.open('userMonitor.asp','_blank','left=3000,top=4000')
}
//window.onunload = monitor
</script>
</head>
<frameset name=forum rows="28,*" noresize scrolling="no" border=0 frameborder="0"  bordercolor="white" framespacing="0" >
<frame name=title src="title.asp" noresize scrolling="no" >
<frameset name=content cols="150,*" noresize scrolling="no" border=0 frameborder="0" framespacing="0">
    <frameset name=menu noresize scrolling="no" border=0 frameborder="0" framespacing="0" rows="20,*">
        <frame name="BoardRefresh" noresize scrolling="no" src="">
        <frame name="BoardTitle" noresize scrolling="no" target="BoardMenu" src="menu.asp">
    </frameset>
    <frame src="main.asp?essenceid=18292" name="BoardMain">
</frameset>
</frameset>
<noframes>
<body>
  sorry ! your browser not support frame!
</body>
</noframes>

</html>


HTTP/1.1 200 OK
Server: Microsoft-IIS/5.0
Date: Tue, 19 Mar 2002 20:04:23 GMT
pragma: no-cache
cache-control: private
Connection: Keep-Alive
Content-Length: 2025
Content-Type: text/html
Expires: Mon, 18 Mar 2002 20:04:22 GMT
Set-Cookie: ASPSESSIONIDGQQQQVCK=GELPBBIBLDCMOIOEAIBHINMB; path=/
Cache-control: no-cache

<!--
    - Dev-club.com开发者俱乐部
    - Based on Active BBS 5.0 By shenpengfei@hotmail.com
    - Last Updated: 2001-12-1
-->

<html>
<head>
<meta HTTP-EQUIV="Content-Type" content="text/html; charset=gb2312">
<link REL="SHORTCUT ICON" href=" HTTP://www.chinaasp.com/icon.ico">
<link rel="stylesheet" type="text/css" href="css/style.CSS">
<title>计算机世界开发者俱乐部</title>
<style>
.navPoint
    {
    font-family: Webdings;
    font-size:9pt;
    color:black;
    cursor:hand;
    }
p{
    font-size:9pt;
}
</style>
<script language="javascript" src="js/rollover.js">
</script>
<script language="javascript">
    var bLoad=false;
    
    function doRefresh(){
        self.frames[1].location="refresh.asp"
        setTimeout("doRefresh()",60000)
    }
    function init(){
        doRefresh()
        //MM_preloadImages('Images/head_about_on.gif','Images/head_course_on.gif','Images/head_partner_on.gif','Images/head_news_on.gif','Images/head_continue_on.gif','Images/head_job_on.gif');
    }
    window.onload = doRefresh
</script>
<script language="javascript1.1" src="js/dcookie.js"></script>
<script>
if (document.all==null) window.location.href="NotIEView.asp?essenceID=18292"
function monitor(){
window.open('userMonitor.asp','_blank','left=3000,top=4000')
}
//window.onunload = monitor
</script>
</head>
<frameset name=forum rows="28,*" noresize scrolling="no" border=0 frameborder="0"  bordercolor="white" framespacing="0" >
<frame name=title src="title.asp" noresize scrolling="no" >
<frameset name=content cols="150,*" noresize scrolling="no" border=0 frameborder="0" framespacing="0">
    <frameset name=menu noresize scrolling="no" border=0 frameborder="0" framespacing="0" rows="20,*">
        <frame name="BoardRefresh" noresize scrolling="no" src="">
        <frame name="BoardTitle" noresize scrolling="no" target="BoardMenu" src="menu.asp">
    </frameset>
    <frame src="main.asp?essenceid=18292" name="BoardMain">
</frameset>
</frameset>
<noframes>
<body>
  sorry ! your browser not support frame!
</body>
</noframes>

</html>

两者只相差头信息而已,速
<script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值