WebRequest, HttpWebRequest 的用法

WebRequest request = WebRequest.Create(http://www.c-sharpcorner.com/index.asp);
WebResponse response = request.GetResponse();
StreamReader reader 
= new StreamReader(response.GetResponseStream());
string str = reader.ReadLine();
while(str != null)
{
Console.WriteLine(str);
str 
= reader.ReadLine();
}


//-------------------------  HttpWebRequest ---------------------------------

HttpWebRequest request 
= (HttpWebRequest)WebRequest.Create (http://www.microsoft.com );
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
String ver 
= response.ProtocolVersion.ToString();
StreamReader reader 
= new StreamReader(response.GetResponseStream() );
string str = reader.ReadLine();
while(str != null)
{
Console.WriteLine(str);
str 
= reader.ReadLine();
}
posted @ 2008-06-24 10:17  CoderZh  阅读(900)  评论(0编辑  收藏  举报