使用webclient.DownloadFileAsync有0KB下载的文件 [英] Downloaded file using webclient.DownloadFileAsync has 0KB

查看:2715
本文介绍了使用webclient.DownloadFileAsync有0KB下载的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想下载的Zend框架(从的 http://framework.zend.com/releases/ZendFramework-1.11.11/ZendFramework-1.11.11.zip ),使用简单

I'm trying to download zend-framework (from http://framework.zend.com/releases/ZendFramework-1.11.11/ZendFramework-1.11.11.zip) using simply

string url = "http://framework.zend.com/releases/ZendFramework-1.11.11/ZendFramework-1.11.11.zip";
WebClient downloader= new WebClient();
downloader.DownloadFileAsync(new Uri(url), "C:\\temp.zip");



的文件被创建,但它是空的。我检查由小提琴手响应,我得到HTTP 200,corrent内容长度,但连接:关闭和提琴手显示-1中的身体列

The file is created, but it is empty. I checked response by fiddler and I get HTTP 200, corrent content-length but "connection: closed" and fiddler shows "-1" in "body" column.

我已经尝试添加用户代理(从谷歌浏览器的请求复制)和连接:保持活动,以头,但是这些帮助非。我也敢肯定,我的程序下载来自同一个地址,这个文件一次或两次才。有由Web客户端触发的事件没有任何错误。

I have tried adding user agent (copied from google chrome request) and "connection: keep-alive" to headers, but non of these helped. I'm also pretty sure, that my program downloaded this file from the same url once or twice before. There are no errors in events fired by webclient.

任何想法?

推荐答案

只是我的猜测:也许你可以尽量保持WebClient的实例,在一些地方不会被垃圾收集。当DownloadFileCompleted事件被炒了,你刚刚清洗参考WebClient的实例,并让GC以后回收内存(不要忘记调用Dispose方法)。

Just my guess: maybe you can try to keep the WebClient instance in some place would not be garbage collected. When the DownloadFileCompleted event fired, you just clean the reference to the WebClient instance and let GC to reclaim the memory later (and don't forget to call Dispose method).

这篇关于使用webclient.DownloadFileAsync有0KB下载的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆