WebClient.DownloadFile 下载动态创建的文件
我有一个动态创建的文件(即我通过处理程序请求它http://example.com/images/1849?encoding=UTF-8&b=100
)它创建基于图像我试图弄清楚如何使用 WebClient.DownloadFile 来获取此文件,但无法使其工作,以前有人这样做过吗?该错误没有告诉我任何信息“System.Net.WebException:WebClient 请求期间发生异常。”
WebClient Client = new WebClient();
Client.DownloadFile("http://example.com/images22?encoding=UTF-8&b=100", @"c:\myfile.jpeg");
I have a file that is dynamically created (ie I request it via a handler http://example.com/images/1849?encoding=UTF-8&b=100
) It creates the image based on what attributes you pass in. I am trying to figure out how to use WebClient.DownloadFile
to grab this file but cannot get it to work has anyone done this before? The error does not tell me anything "System.Net.WebException: An exception occurred during a WebClient request."
WebClient Client = new WebClient();
Client.DownloadFile("http://example.com/images22?encoding=UTF-8&b=100", @"c:\myfile.jpeg");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无法发表评论,需要代表...
您是否尝试过将
DownloadFile
包装在Try / Catch
块中,然后显示错误详细信息?具体来说,是 HTTP 错误还是其他系统错误?Can't comment, need rep...
Have you tried wrapping the
DownloadFile
in aTry / Catch
block and then displaying the error details? Specifically, if it's a HTTP error, or some other system error?第二个字符串参数是要下载到的本地文件,例如
C:\image.bmp
。如果您想要使用字节数组,则可以改用
DownloadData
。The second string parameter is a local file to download to, such as
C:\image.bmp
.You could instead use
DownloadData
if you want a byte array to work with instead.