如何下载使用URL与查询字符串,而不是图像路径的图像? [英] How to download an image using a URL with a query string instead of image path?

查看:207
本文介绍了如何下载使用URL与查询字符串,而不是图像路径的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一个C#Windows应用程序,并且需要知道如何下载它有一个查询字符串链接的图片,例如 www.mywebsite.com/img.aspx?imgid= 12345 (自动重定向到基于 imgid 相应的图像)。我需要然后将该文件保存到磁盘的某个地方。我不需要任何大花式的下载管理器,只是从一个重定向URL这样的图像最清晰的方式。

I'm doing a C# windows application, and need to know how to download a picture which has a link with a query string, for example www.mywebsite.com/img.aspx?imgid=12345 (which automatically redirects to the appropriate image based on imgid). I need to then save the file to the disk somewhere. I don't need any big fancy download manager, just the cleanest way to get such an image from a redirecting URL.

推荐答案

你应该能够做到这一点是这样的:使用(Web客户端的客户端=新的WebClient())

You should be able to do it like this:

using (WebClient Client = new WebClient ())
{
    Client.DownloadFile("http://www.mywebsite.com/img.aspx?imgid=12345", "12345.jpg");
}

这篇关于如何下载使用URL与查询字符串,而不是图像路径的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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