WebClient.DownloadFile 下载动态创建的文件

发布于 2025-01-08 00:29:09 字数 383 浏览 3 评论 0原文

我有一个动态创建的文件(即我通过处理程序请求它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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故事和酒 2025-01-15 00:29:09

无法发表评论,需要代表...

您是否尝试过将 DownloadFile 包装在 Try / Catch 块中,然后显示错误详细信息?具体来说,是 HTTP 错误还是其他系统错误?

Can't comment, need rep...

Have you tried wrapping the DownloadFile in a Try / Catch block and then displaying the error details? Specifically, if it's a HTTP error, or some other system error?

云柯 2025-01-15 00:29:09

第二个字符串参数是要下载到的本地文件,例如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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文