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:
/// <summary>
/// 保存文件到本地
/// </summary>
/// <param name="filePath">uri</param>
/// <param name="folderPath">localDir</param>
/// <param name="localFilePath">folderPath+fileName</param>
public void SaveDownFile(string filePath, string folderPath, string localFilePath)
{
try
{
if (!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
}
WebClient DownFile = new WebClient();
DownFile.DownloadFile(filePath, localFilePath);
logger.WriteSystemLog(LogLevel.Const, "successfully saveDownFile:" + localFilePath);
}
catch (Exception ex)
{
logger.WriteExceptionLog(ex, " saveDownFile Exception: httpUrl=" + filePath);
}
}
public static long userId = ;
public static string userCode;
public static string token;
public static string clientIP;
// 单点登录
protected void sso()
{
clientIP = GetClientIP();// local IP
userId = GetUserId();
userCode = GetUserCode();
token = sendMessage(userId, userCode, clientIP);// 发送验证消息 if (!string.IsNullOrEmpty(token))
{
delayTime();
simLogin(token);
}
} // 登录
private void simLogin(string token)
{
var url = string.Format("http://192.168.12.250:8900/Login?userId={0}&clientIP={1}&token={2}", userCode, clientIP, token);
WebClient wc = new WebClient();
byte[] ret = wc.DownloadData(url);
} private void delayTime(double secend)
{
DateTime tempTime = DateTime.Now;
while (tempTime.AddSeconds(secend).CompareTo(DateTime.Now) > )
System.Windows.Forms.Application.DoEvents();
}
C#WebClient常见用法的更多相关文章
- Linux中find常见用法
Linux中find常见用法示例 ·find path -option [ -print ] [ -exec -ok command ] {} \; find命令的参数 ...
- php中的curl使用入门教程和常见用法实例
摘要: [目录] php中的curl使用入门教程和常见用法实例 一.curl的优势 二.curl的简单使用步骤 三.错误处理 四.获取curl请求的具体信息 五.使用curl发送post请求 六.文件 ...
- Guava中Predicate的常见用法
Guava中Predicate的常见用法 1. Predicate基本用法 guava提供了许多利用Functions和Predicates来操作Collections的工具,一般在 Iterabl ...
- find常见用法
Linux中find常见用法示例 ·find path -option [ -print ] [ -exec -ok command ] {} \; find命令的参数 ...
- iOS 开发多线程篇—GCD的常见用法
iOS开发多线程篇—GCD的常见用法 一.延迟执行 1.介绍 iOS常见的延时执行有2种方式 (1)调用NSObject的方法 [self performSelector:@selector(run) ...
- iOS开发多线程篇—GCD的常见用法
iOS开发多线程篇—GCD的常见用法 一.延迟执行 1.介绍 iOS常见的延时执行有2种方式 (1)调用NSObject的方法 [self performSelector:@selector(run) ...
- [转]EasyUI——常见用法总结
原文链接: EasyUI——常见用法总结 1. 使用 data-options 来初始化属性. data-options是jQuery Easyui 最近两个版本才加上的一个特殊属性.通过这个属性,我 ...
- NSString常见用法总结
//====================NSStirng 的常见用法==================== -(void)testString { //创建格式化字符串:占位符(由一个%加一个字 ...
- [转]Linux中find常见用法示例
Linux中find常见用法示例[转]·find path -option [ -print ] [ -exec -ok command ] {} \;find命令的参 ...
随机推荐
- 使用Firefox user agent进行移动端网页测试
Selenium 真是个强大的网页测试工具,设置Firefox user agent, 就可以轻松模拟手机端浏览器进行网页测试. Demo Code # -*- coding:utf8 -*- imp ...
- TopShelf&Quartz.Net实现多任务的值守
很多时候,我们需要为一个服务器安装一堆的服务,来监控各种数据. 在windows服务器里,我们会部署专门的Quartz.Net多任务轮询服务. 同时,我们针对不同的任务制作专门的***Job.dll, ...
- 【转】编译quickfast解析库(沪深level2行情转码库)
转自http://blog.csdn.net/hacode/article/details/7065889 编译quickfast解析库(沪深level2行情转码库) 目录(?)[-] 1 下载源代 ...
- Eclipse *版本
关于Eclipse的版本介绍, Eclipse Standard 该版本是eclipse最基础的版本,适合Java se个人开发者.或希望根据自己需求配置插件的开发者使用. Eclipse IDE f ...
- VC运行库合集2005/2008/2010/2012/2013/2015
VC运行库合集2005/2008/2010/2012/2013/2015,批处理一键安装(需管理员权限) 链接:http://pan.baidu.com/s/1bpLZoFt 密码:bnk8
- Glide 下载Gif文件
之前做了一个类似朋友圈里的查看大图功能,现在也要加上保存功能. 保存图片有很多思路,可以从imageview里提取bitmap,可以用url下载到本地.imageview提取的话,gif图就会变成一张 ...
- volley_之2
一开始会不会觉得有点怔,为什么只需要将请求添加到队列中,不需要去发送请求吗?当然是要的,只是这一切都被封装在Volley后面而已. 我们先来看一下隐藏在Volley后面的这个架构是怎么样的吧,如下图: ...
- windows下使用VS2010编译jpeglib
1.下载源代码下载地址:http://www.ijg.org/files/, 选择最新版本的windows版本压缩包,进行下载. jpegsr9a.zip 1042 Kb Su ...
- sql(转自http://www.imooc.com/article/2325)
http://www.imooc.com/article/2325
- Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
今天碰到了一个查询异常问题,上网查了一下,感谢原创和译者 如果你使用的数据库连接类是 the Data Access Application Blocks "SqlHelper" ...