• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C#WebClient常见用法

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

System.Net.WebClient.DownloadFile(Uri address, String fileName)

namespace:System.Net

参数:

address:The URI from which to download data.
fileName:The name of the local file that is to receive the data.

eg:

 1 /// <summary>
 2 /// 保存文件到本地
 3 /// </summary>
 4 /// <param name="filePath">uri</param>
 5 /// <param name="folderPath">localDir</param>
 6 /// <param name="localFilePath">folderPath+fileName</param>
 7 public void SaveDownFile(string filePath, string folderPath, string localFilePath)
 8 {
 9     try
10     {
11         if (!Directory.Exists(folderPath))
12         {
13             Directory.CreateDirectory(folderPath);
14         }
15         WebClient DownFile = new WebClient();
16         DownFile.DownloadFile(filePath, localFilePath);
17         logger.WriteSystemLog(LogLevel.Const, "successfully saveDownFile:" + localFilePath);
18     }
19     catch (Exception ex)
20     {
21         logger.WriteExceptionLog(ex, " saveDownFile Exception: httpUrl=" + filePath);
22     }
23 }

 

 1 public static long userId = 1;
 2 public static string userCode;
 3 public static string token;
 4 public static string clientIP;
 5 // 单点登录
 6 protected void sso()
 7 {
 8     clientIP = GetClientIP();// local IP
 9     userId = GetUserId();
10     userCode = GetUserCode();
11     token = sendMessage(userId, userCode, clientIP);// 发送验证消息
12 
13     if (!string.IsNullOrEmpty(token))
14     {
15         delayTime(2);
16         simLogin(token);
17     }
18 }
19 
20 // 登录
21 private void simLogin(string token)
22 {
23     var url = string.Format("http://192.168.12.250:8900/Login?userId={0}&clientIP={1}&token={2}", userCode, clientIP, token);
24     WebClient wc = new WebClient();
25     byte[] ret = wc.DownloadData(url);
26 }
27 
28 private void delayTime(double secend)
29 {
30     DateTime tempTime = DateTime.Now;
31     while (tempTime.AddSeconds(secend).CompareTo(DateTime.Now) > 0)
32         System.Windows.Forms.Application.DoEvents();
33 }

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C语言练习题_邮票组合发布时间:2022-07-13
下一篇:
C++中的迭代器发布时间:2022-07-13
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap