zoukankan      html  css  js  c++  java
  • C#WebClient常见用法

    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 }
  • 相关阅读:
    强制位与冒险位
    完美图解教程 Linux环境VNC服务安装、配置与使用
    Linux 最常用命令
    return 与 exit()的区别return退出本函数,exit()退出整个程序
    Linux标准目录配置(转自鸟哥)
    Hadoop C访问
    Shell学习总结
    为 Linux 应用程序编写 DLL(在仅仅只会编写插件的时候为什么要编写整个应用程序?)
    SteveY对Amazon和Google平台的长篇大论
    gcc环境变量基础
  • 原文地址:https://www.cnblogs.com/wuln/p/6231635.html
Copyright © 2011-2022 走看看