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();
            }
        }
    }
  • 相关阅读:
    人月神话阅读笔记03(完)
    人月神话阅读笔记02
    各种前端好用的在线工具、学习网站、插件
    垂直居中css
    输入框判断表情的输入js
    jq九宫格抽奖
    移动端中一像素的解决方案
    获取url地址栏中的参数数据
    ios中getTime()的兼容性问题
    清除Css中select的下拉箭头样式
  • 原文地址:https://www.cnblogs.com/chenqingwei/p/1699300.html
Copyright © 2011-2022 走看看