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);
  • 相关阅读:
    作用域和内存问题
    Javascript事件
    JavaScript学习总结(三)
    Javascript学习总结(二)
    JavaScript学习总结(一)
    vue开发搭建 1、 npm安装+vue脚手架安装 2、cnpm安装
    20181008
    RabbitMQ在.NetCore中的基础应用
    微软CRM 基于 ADFS自定义多重身份验证
    如何在ASP.NET Core中上传超大文件
  • 原文地址:https://www.cnblogs.com/coderzh/p/1340794.html
Copyright © 2011-2022 走看看