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)
![](http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)![](http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)Console.WriteLine(str);
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)str 
= reader.ReadLine();
![](http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)}



//-------------------------  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)
![](http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)![](http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)Console.WriteLine(str);
![](http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)str 
= reader.ReadLine();
![](http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)}

[温馨提示]:该文章由原博客园导入而来,如排版效果不佳,请移步:http://www.cnblogs.com/coderzh/archive/2008/06/24/1228675.html

微信扫一扫交流

作者:CoderZh
微信关注:hacker-thinking (一个程序员的思考)
本文出处:https://blog.coderzh.com/2008/06/24/1228675/
文章版权归本人所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。