许明会的计算机技术主页

Language:C,C++,.NET Framework(C#)
Thinking:Design Pattern,Algorithm,WPF,Windows Internals
Database:SQLServer,Oracle,MySQL,PostSQL
IT:MCITP,Exchange,Lync,Virtualization,CCNP

导航

TCP编程(3): WebRequest, WebResponse

/*--===------------------------------------------===---
WebRequest, WebResponse

            许明会    23:51:45 2007年12月9日
--===------------------------------------------===---
*/
using System;
using System.Net;
using System.Text;
using System.IO;

namespace xumh
{
    
public class runMyApp
    {
        
static void Main()
        {
            
string strUriBaidu = @"http://www.baidu.com";
            WebRequest req 
= WebRequest.Create(strUriBaidu);
            WebResponse res 
= req.GetResponse();
            Stream srm 
= res.GetResponseStream();
            System.Text.Encoding ec 
= Encoding.GetEncoding(936);
            StreamReader sr 
= new StreamReader(srm,ec);
            System.Text.StringBuilder sb 
= 
                
new System.Text.StringBuilder();

            
char[] buff = new char[256];
            
int nCount = sr.Read(buff,0,256);
            
while(nCount>0)
            {
                sb.Append(
new string(buff,0,nCount));
                nCount 
= sr.Read(buff,0,256);
            }
            Console.WriteLine(sb.ToString());
            
//

        }
    };
}

posted on 2007-12-09 23:53  许明会  阅读(254)  评论(0编辑  收藏  举报