Wednesday, February 27, 2013

System.Net.WebException : Cannot handle redirect from HTTP/HTTPS protocols to other dissimilar ones.

Currently I am writing an integration test that enters a scenario into the database, then invokes a url on my web site, and then checks to make sure the database has been updated properly.   While doing this I ran across this error:
System.Net.WebException : Cannot handle redirect from HTTP/HTTPS protocols to other dissimilar ones.
My C# code looked like this:

string webPageText;
 using (WebClient client = new WebClient())
 {
    webPageText = client.DownloadString("http://www.myserver.com/appname/params");
 }

It took me too long to understand the error message.  The real problem is that my app was issuing a 302 redirect and my C# code doesn't know how to handle that.  It failed the unit test, which is what it should have done.  Once I corrected my input, the redirect to an error page was not raised, and my test passed.




No comments: