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

  • 相关阅读:
    win10安装mongodb教程及其失败解决方案
    基于TypeScript的NodeJs框架:NestJs开发博客API (node.js+nest.js)
    Webpack性能改造之CDN
    44道JavaScript送命题
    electron-vue学习手册
    万字长文带你深度解锁Webpack(进阶篇)
    4W字长文带你深度解锁Webpack系列(上)
    devexpress GalleryControl 获得选中的item并删除
    c# 任意角度旋转图片
    .net core3.1连接GBase数据库的步骤
  • 原文地址:https://www.cnblogs.com/chenxiulou/p/4624603.html
Copyright © 2011-2022 走看看