zoukankan      html  css  js  c++  java
  • webclient 和 webrequest获取网页源码的

    private void WebClientButton_Click(object sender, System.EventArgs e)
    {
    PageUrl = UrlText.Text;
    WebClient wc = new WebClient();
    wc.Credentials = CredentialCache.DefaultCredentials;

    ///方法一:
    Byte[] pageData = wc.DownloadData(PageUrl);
    ContentHtml.Text = Encoding.Default.GetString(pageData);

    /// 方法二:
    /// ***************代码开始**********
    /// Stream resStream = wc.OpenRead(PageUrl);
    /// StreamReader sr = new StreamReader(resStream,System.Text.Encoding.Default);
    /// ContentHtml.Text = sr.ReadToEnd();
    /// resStream.Close();
    /// **************代码结束********
    ///
    wc.Dispose();
    }

    private void WebRequestButton_Click(object sender, System.EventArgs e)
    {
    PageUrl = UrlText.Text;
    WebRequest request = WebRequest.Create(PageUrl);
    WebResponse response = request.GetResponse();
    Stream resStream = response.GetResponseStream();
    StreamReader sr = new StreamReader(resStream, System.Text.Encoding.Default);
    ContentHtml.Text = sr.ReadToEnd();
    resStream.Close();
    sr.Close();
    }

  • 相关阅读:
    CF375D Tree and Queries
    进制转换
    贪心问题
    next_permutation函数
    C++ STL
    一些排序总结
    KMP算法
    围圈报数
    车辆调度—模拟栈的操作
    搜索题
  • 原文地址:https://www.cnblogs.com/tiancai/p/2938386.html
Copyright © 2011-2022 走看看