大家知道,用HttpWebRequest可以通过Http对网页进行抓取,但是如果是内网,而且是通过代理上网的用户,如果直接进行操作是行不通的。那有没有什么办法呢?当然有,呵呵,见以下代码:string urlStr = "http://www.domain.com"; //設定要獲取的地址HttpWebRequest hwr = (HttpWebRequest)HttpWebRequest.Create(urlStr); //建立HttpWebRequest對象hwr.Timeout = 60000; //定義服務器超時時間WebProxy proxy = new WebProxy(); //定義一個網關對象proxy.Address = new Uri("http://proxy.domain.com:3128"); //網關服務器:端口proxy.Credentials = new NetworkCredential("f3210316", "6978233"); //用戶名,密碼hwr.UseDefaultCredentials = true; //啟用網關認証hwr.Proxy = proxy; //設置網關HttpWebResponse hwrs = (HttpWebResponse)hwr.GetResponse(); //取得回應Stream s = hwrs.GetResponseStream(); //得到回應的流對象StreamReader sr = new StreamReader(s, Encoding.UTF8); //以UTF-8編碼讀取流StringBuilder content = new StringBuilder(); //while (sr.Peek() != -1) //每次讀取一行,直到{ //下一個字節沒有內容 content.Append(sr.ReadLine()+"\r\n"); //返回為止} //return content.ToString() ; //返回得到的字符串 转载于:https://www.cnblogs.com/leonny/archive/2007/06/21/791435.html