zoukankan      html  css  js  c++  java
  • WebClient

    参考链接:http://www.cnblogs.com/hfliyi/archive/2012/08/21/2649892.html

    /// <summary>
    /// 读取指定uri的html
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Button1_Click(object sender, EventArgs e)
    {
    WebClient wc = new WebClient();
    string uri = "http://www.baidu.com";
    Stream stream = wc.OpenRead(uri);
    StreamReader sr = new StreamReader(stream);
    string result = "";
    while (!string.IsNullOrEmpty(result = sr.ReadLine()))
    {
    Response.Write(result);
    }
    sr.Close();
    }
    /// <summary>
    /// 向指定Uri写入数据
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Button2_Click(object sender, EventArgs e)
    {
    WebClient wc = new WebClient();
    string uri = "E:/a.txt";
    Stream stream = wc.OpenWrite(uri, "PUT");
    StreamWriter sw = new StreamWriter(stream);
    sw.WriteLine("WebClinet的测试");
    sw.Flush();
    sw.Close();
    Response.Write("OK ");
    }
    /// <summary>
    /// 把本地文件上传到指定的Uri
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Button3_Click(object sender, EventArgs e)
    {
    WebClient wc = new WebClient();
    string targePath = "F:/a.txt";
    string sourcePath = "E:/a.txt";
    byte[] bt = wc.UploadFile(targePath, "PUT", sourcePath);
    Response.Write(Encoding.ASCII.GetString(bt));
    }
    /// <summary>
    /// 把数据缓冲区上载到指定资源
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Button4_Click(object sender, EventArgs e)
    {
    WebClient wc = new WebClient();
    string targePth = "F:/QQ截图20150320192104.png";
    string sourcePath = "E:/一刻印记.jpg";
    FileStream fs = new FileStream(sourcePath, FileMode.Open, FileAccess.Read);
    byte[] bt = new byte[fs.Length];
    fs.Read(bt, 0, bt.Length);
    wc.UploadData(targePth, bt);
    }

  • 相关阅读:
    vue——样式穿透/deep/ >>> ::v-deep 三者的区别
    CSS Grid 网格布局教程
    CSS3中的display:grid网格布局介绍
    windows 好用的命令
    django分页
    django.template.exceptions.TemplateSyntaxError: 'staticfiles' is not a registered tag library. Must
    bootstrap模板
    django报错 django.core.exceptions.ImproperlyConfigured: mysqlclient 1.4.0 or newer is required; you have 0.10.1
    bootstrapV4.4.1版本下载
    Dots demo解释相关
  • 原文地址:https://www.cnblogs.com/xiaocandou/p/4389522.html
Copyright © 2011-2022 走看看