Error when downloading a file from website using csharp Too many automatic redirections were attempted

Chocolade

Distinguished
Dec 13, 2010
41
0
18,530
The error is: Too many automatic redirections were attempted

I know this is not a csharp forum but the problem is seems to be with the website i'm trying to download from. I'm not sure but i think the problem is in the site.
In general i'm downloading using a timer every 5 minutes the same image from a website.

The website is: http://

If i'm surfing to the website with chrome and make save as on the image there is no problem to download the image.

But from my program in csharp i'm getting all the time 99% of the times error:

Too many automatic redirections were attempted

I used a program called fiddler and i got this results:

# Result Protocol Host URL Body Caching Content-Type Process Comments Custom
31 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768
32 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768
33 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768
34 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768
35 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768
36 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768
37 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768
38 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768
39 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768
40 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768
41 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768
42 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768
43 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768
44 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768
45 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768
46 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768
47 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768
48 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768
49 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768
50 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768
51 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768
52 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768
53 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768
54 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768
55 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768
56 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768
57 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768
58 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768
59 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768
60 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768
61 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768
62 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768
63 302 HTTP www.ims.gov.il /Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location= 0 my weather station.vshost:6768



The question is if i can by pass somehow this problem if it's on the site side ?
In csharp i'm just using the regular WebClient to download the file nothing speical.

private void fileDownloadRadar()
{
if (Client.IsBusy == true)
{
Client.CancelAsync();
}
else
{
Client.DownloadFileAsync(myUri, combinedTemp);
}
}


 
Solution
Odd that it would work sometimes and not others. Here's method for sanitizing the URI: http://msdn.microsoft.com/en-us/library/system.uri.escapeuristring%28v=vs.110%29.aspx

Since it's only happening sometimes and not always (but it's always the same URL?) I'm wondering if they're doing a redirect when the image isn't available. You could try toggling your setting for how you respond to redirects. Figure out what it's set at now and change it to the opposite and see what happens: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.allowautoredirect(v=vs.110).aspx ?

Chocolade

Distinguished
Dec 13, 2010
41
0
18,530


I never checked it. Since some times it's working and downloading the file without a problem i didn't think about this.
How should i do it ? If you could show me an example.
 

adamwinn

Distinguished
Dec 31, 2007
245
0
18,860
Odd that it would work sometimes and not others. Here's method for sanitizing the URI: http://msdn.microsoft.com/en-us/library/system.uri.escapeuristring%28v=vs.110%29.aspx

Since it's only happening sometimes and not always (but it's always the same URL?) I'm wondering if they're doing a redirect when the image isn't available. You could try toggling your setting for how you respond to redirects. Figure out what it's set at now and change it to the opposite and see what happens: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.allowautoredirect(v=vs.110).aspx ?
 
Solution