Webclient
using System;
using System.Collections.Generic;
using System.Net;
using System.Text;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
TestWebclient testWebclient = new TestWebclient();
testWebclient.WebClientUpload();
//WebClientDownload();
//WebClientUpload();
//WebClientDelete();
Console.ReadKey();
}
#region 下载
/// <summary>
/// 下载
/// </summary>
static void WebClientDownload()
{
WebClient webClient = new WebClient
{
Credentials = CredentialCache.DefaultCredentials
};
//Uri _uri = new Uri(@"http://localhost:8082/123.txt");
Uri uri = new Uri(@"http://192.168.0.100:8082/123.txt");
webClient.DownloadProgressChanged += WebClient_DownloadProgressChanged;
webClient.DownloadFileCompleted += WebClient_DownloadFileCompleted;
webClient.DownloadFileAsync(uri, @"D:\download\123.txt");
}
private static void WebClient_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
Console.WriteLine("下载完成...");
}
private static void WebClient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
Console.WriteLine($"{e.ProgressPercentage}:{e.BytesReceived}/{e.TotalBytesToReceive}");
}
#endregion
#region 上传
/// <summary>
/// 上传
/// </summary>
static void WebClientUpload()
{
WebClient webClient = new WebClient
{
Credentials = new NetworkCredential("test", "123")
};
Uri uri = new Uri(@"http://192.168.0.100:8082/456.xlsx");
webClient.UploadProgressChanged += WebClient_UploadProgressChanged;
webClient.UploadFileCompleted += WebClient_UploadFileCompleted;
webClient.UploadFileAsync(uri, "PUT", @"D:\download\456.xlsx");
}
private static void WebClient_UploadFileCompleted(object sender, UploadFileCompletedEventArgs e)
{
Console.WriteLine("上传完成...");
}
private static void WebClient_UploadProgressChanged(object sender, UploadProgressChangedEventArgs e)
{
Console.WriteLine($"{e.ProgressPercentage}:{e.BytesSent}/{e.TotalBytesToSend}");
}
#endregion
#region 删除
/// <summary>
/// 删除
/// </summary>
static void WebClientDelete()
{
WebClient webClient = new WebClient
{
Credentials = new NetworkCredential("test", "123")
};
Uri uri = new Uri(@"http://192.168.0.100:8082/456.xlsx");
webClient.UploadDataCompleted += WebClient_UploadDataCompleted;
webClient.UploadDataAsync(uri, "DELETE", new byte[0]);
}
private static void WebClient_UploadDataCompleted(object sender, UploadDataCompletedEventArgs e)
{
Console.WriteLine("已删除...");
}
#endregion
}
}
相关文章
- CRM WebClient UI里Sales area的保存原理
- SAP CRM WebClient UI 支持的一些 url 参数
- SAP WebClient UI页面标签的决定逻辑介绍
- 在SAP WebClient UI里使用AJAX进行异步数据读取
- SAP CRM WebClient UI,如何快速定位到抛出错误消息的那一行代码
- SAP CRM WebClient UI cross component跳转的一个具体例子
- SAP CRM WebClient UI根据扩展字段搜索出结果的实现原理
- SAP CRM WebClient UI SSO cookie
- Checkpoint IC_WEBCLIENT_PROCESS_CNTRL_DBG
- SAP CRM WebClient UI CL_BSP_MESSAGES
- 快速定位Webclient UI 登陆business role之后timeout问题
- 打印user webclient ui浏览历史的工具
- WebClient UI MVC data binding的实现
- CRM webClient UI搜索参数里max hit是怎么被后台服务器处理的
- 如何在CRM WebClient UI里打开外部链接