zoukankan      html  css  js  c++  java
  • WebClient类--上传文件

     #region 把本地文件上传到指定uri
    2         /// <summary>
    3         /// 把本地文件上传到指定uri
    4         /// </summary>
    5         /// <param name="sender"></param>
    6         /// <param name="e"></param>
    7         private void button2_Click(object sender, EventArgs e)
    8         {
    9             WebClient wc = new WebClient();
    10             string targetPath = "http://127.0.0.1/rss/Data Configuration.zip";
    11             string sourcePath = "d:\Data Configuration.zip";
    12             this.label1.Text = string.Format("uploading {0} to {1}", targetPath, sourcePath);
    13             byte[] bt = wc.UploadFile(targetPath, "PUT", sourcePath);
    14             MessageBox.Show("OK");
    15         }
    16         #endregion
    17
    18
    19         #region 把数据缓冲区上载到指定资源
    20         /// <summary>
    21         /// 把数据缓冲区上载到指定资源
    22         /// </summary>
    23         /// <param name="sender"></param>
    24         /// <param name="e"></param>
    25         private void button3_Click(object sender, EventArgs e)
    26         {
    27             WebClient wc = new WebClient();
    28             string targetPath = "http://127.0.0.1/rss/kaifeng.jpg";
    29             string sourcePath = @"C: est.jpg";
    30             FileStream fs = new FileStream(sourcePath, FileMode.Open, FileAccess.Read);
    31             byte[] bt = new byte[fs.Length];
    32             fs.Read(bt, 0, bt.Length);
    33             wc.UploadData(targetPath, "PUT", bt);
    34         }
    35         #endregion

  • 相关阅读:
    在Xsheel Linux上安装nodejs和npm
    判断js中的数据类型的几种方法
    Sequelize 中文API文档-1. 快速入门、Sequelize类
    php中 ob_start()有什么作用
    PHP错误类型及屏蔽方法
    ajax对象的获取及其常用属性
    linux工作笔记
    Redis和Memcached的区别
    MySQL架构
    Http协议三次握手过程
  • 原文地址:https://www.cnblogs.com/chenxiulou/p/4624603.html
Copyright © 2011-2022 走看看