zoukankan      html  css  js  c++  java
  • C#用HttpWebRequest通过代理服务器验证后抓取网页内容 。。。。。

    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() ;                                            //返回得到的字符串
  • 相关阅读:
    php无限极分类
    HDU 1176 免费馅饼 (类似数字三角形的题,很经典,值得仔细理解的dp思维)
    HDU 1158(非常好的锻炼DP思维的题目,非常经典)
    HDU 1165 公式推导题
    HDU 1069 Monkey and Banana(转换成LIS,做法很值得学习)
    HDU 1059(多重背包加二进制优化)
    HDU 1058(打表)
    oracle11g之管理oracle数据库笔记(理论基础知识)
    oracle11g之Oracle体系结构(理论基础知识)
    HDU 1025 LIS二分优化
  • 原文地址:https://www.cnblogs.com/Fooo/p/818189.html
Copyright © 2011-2022 走看看