zoukankan      html  css  js  c++  java
  • C# 发送Http请求 WebClient类

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

    一、用法1 - DownloadData

    string uri = "http://coderzh.cnblogs.com";
    WebClient wc 
    = new WebClient();
    Console.WriteLine(
    "Sending an HTTP GET request to " + uri);
    byte[] bResponse = wc.DownloadData(uri);
    string strResponse = Encoding.ASCII.GetString(bResponse);
    Console.WriteLine(
    "HTTP response is: ");
    Console.WriteLine(strResponse);

    二、用法2 - OpenRead

    string uri = " http://coderzh.cnblogs.com";
    WebClient wc 
    = new WebClient();
    Console.WriteLine(
    "Sending an HTTP GET request to " + uri);
    Stream st 
    = wc.OpenRead(uri);
    StreamReader sr 
    = new StreamReader(st);
    string res = sr.ReadToEnd();
    sr.Close();
    st.Close();
    Console.WriteLine(
    "HTTP Response is ");
    Console.WriteLine(res);
  • 相关阅读:
    LVS---服务器集群系统
    I/O的基本概念
    rsync+cron同步文件服务
    IAAS、PAAS、SAAS及公有云、私有云概念
    Python3456学习结构
    Python列表常用函数解析
    Python字符串常用函数详解
    验证码生成
    Python随机数生成random.randint()与np.random.randint()
    python在线&离线安装第三库的方法
  • 原文地址:https://www.cnblogs.com/coderzh/p/1340794.html
Copyright © 2011-2022 走看看