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();
            }
        }
    }
  • 相关阅读:
    单例模式的几种写法 总结
    TCP的三次握手与四次挥手总结(详解+动图) 面试准备
    向mysql插入表中的中文显示为乱码或问号的解决方法,亲测有用!!
    再论红黑树
    jQuery插件机制
    jQuery高级案例
    jQuery事件绑定与切换
    jQuery动画和遍历
    jQuery基础案例
    DOM操作
  • 原文地址:https://www.cnblogs.com/chenqingwei/p/1699300.html
Copyright © 2011-2022 走看看