通过code,有重定向下载文件? [英] Download file through code that has a redirect?
问题描述
我在数据库中有一些网址。这个问题是存在的URL是重定向到我想要的网址。
I have some urls in the database. The problem is there urls are urls that redirect to what I want.
我有这样的事情
http://www.mytestsite.com/test/test/?myphoto=真正的
现在,如果我去这个网站它会做一个重定向到的照片,以便该URL将最终被
now if I go to this site it would do a redirect to the photo so the url would end up being
http://www.mytestsite.com/test/myphoto.jpg
是否有可能以某种方式刮(下载)到C#,然后把它重定向,并得到真正的URL,这样我可以下载图片?
Is it possible to somehow scrape(download) through C# and then have it redirect and get the real url so I can download the image?
推荐答案
我觉得你是在<一个href="http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.allowautoredirect.aspx">HttpWebRequest.AllowAutoRedirect属性。该属性获取或设置一个值,该值指示请求是否应跟随重定向响应。
I think you are after the HttpWebRequest.AllowAutoRedirect Property. The property gets or sets a value that indicates whether the request should follow redirection responses.
示例从MSDN采取
HttpWebRequest myHttpWebRequest=(HttpWebRequest)WebRequest.Create("http://www.contoso.com");
myHttpWebRequest.MaximumAutomaticRedirections=1;
myHttpWebRequest.AllowAutoRedirect=true;
HttpWebResponse myHttpWebResponse=(HttpWebResponse)myHttpWebRequest.GetResponse();
这篇关于通过code,有重定向下载文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!