zoukankan      html  css  js  c++  java
  • WebClient位于System.Net命名空间下,通过这个类可以方便的创建Http请求并获取返回内容。

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Net;
    using System.IO;

    namespace ConsoleWebClient
    {
        
    class Program
        {
            
    static void Main(string[] args)
            {
                
    string uri = "http://www.cnblogs.com";
                WebClient wc 
    = new WebClient();
                Stream st 
    = wc.OpenRead(uri);
                StreamReader sr 
    = new StreamReader(st);
                
    string res = sr.ReadToEnd();
                sr.Close();
                st.Close();
                Console.WriteLine(res);
                Console.ReadKey();
            }

            
    public void ReadPageContent()
            {
                
    string uri = "http://www.cnblogs.com";
                WebClient wc 
    = new WebClient();
                
    byte[] bResponse = wc.DownloadData(uri);
                
    string strResponse = Encoding.UTF8.GetString(bResponse);
                Console.WriteLine(strResponse);
                Console.ReadKey();
            }
        }
    }
  • 相关阅读:
    POJ 2411 Mondriaan's Dream
    POJ 2505 A multiplication game
    HDOJ(HDU) 3949 XOR
    雅礼集训DAY 6 T1 xmasdag
    bzoj 2159: Crash 的文明世界
    如何查看Ubuntu版本
    Ubuntu如何安装谷歌Chrome浏览器
    使用nano编辑器进行查找和替换
    Ubuntu修改用户和root密码
    Anaconda/Conda创建环境时报错的解决方案
  • 原文地址:https://www.cnblogs.com/chenqingwei/p/1699300.html
Copyright © 2011-2022 走看看