Robin's Blog

记录 积累 学习 成长

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

 try
            {
                WC 
= new System.Net.WebClient();
                
//实例化代理服务器对象
                WebProxy myProxy = new WebProxy(@"http://192.168.0.1:8080",true);
                
// 设置用户帐号username,password
                myProxy.Credentials = new NetworkCredential("username""password");
                
// 为WebClient设置proxy
                WC.Proxy  = myProxy;
                s 
= WC.OpenRead(url);
                sr 
= new System.IO.StreamReader(s);
                CodeSource 
= sr.ReadToEnd();
                sr.Close();
                sr.Dispose();
                s.Close();
                s.Dispose();
            }
            
catch (Exception ex)
            {
                
if (ex.Message.ToString().Contains("401"))
                    MessageBox.Show(
"Web Access denied (Unauthorized)");
                
else
                    MessageBox.Show(ex.Message);
            }
            
finally
            {
                WC.Dispose();
posted on 2009-03-26 13:50  Robin99  阅读(789)  评论(0编辑  收藏  举报