I had the same thing as me today.
Using a WebClient object to verify that the URL is returning something.
But my experience is different. I tried to remove Accept-Encoding, mostly using the @Antonio Bakula code that gave in his answer. But every time I got the same error (InvalidOperationException)
So this did not work:
WebClient wc = new WebClient(); wc.Headers.Add("Accept-Encoding", ""); string result = wc.DownloadString(url);
But adding "any" text as a User Agent instead did the trick. This works great:
WebClient wc = new WebClient(); wc.Headers.Add(HttpRequestHeader.UserAgent, "My User Agent String"); System.IO.Stream stream = wc.OpenRead(url);
Your mileage may vary, obviously, also in the note. I am using ASP.NET 4.0.30319.
source share