Reputation: 5907
I´m a little confused about my code because from time to time I get an Http 500 error message. I know what an http 500 error (a Server error) is, but I want to be sure that my code is not the problem.
Do you think there could be something wrong with my code?
request = (HttpWebRequest)WebRequest.Create(testurls[samplenumber, j]);
System.Net.NetworkCredential netCred = new System.Net.NetworkCredential(test_user, test_pass, test_domain);
request.Timeout = 60000;
request.Headers.Add("HTTP_USER_AGENT", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)");
request.MaximumAutomaticRedirections = 50 ;
request.MaximumResponseHeadersLength = 64 ;
request.Method = "GET";
CookieContainer cookieContainer = new CookieContainer();
request.CookieContainer = cookieContainer;
response = request.GetResponse();
Stream stream = response.GetResponseStream();
stream.Close();
stream.Dispose();
response.Close();
Upvotes: 0
Views: 178
Reputation: 8474
It looks like your URLs come from a matrix. I don't know how many but likely some of them take you to pages that are returning HTTP 500 status code. Try logging those pages...
embed your code in a try catch block like this.
try
{
}
catch (WebException)
{
// set a breakpoint here
}
And when the program stops in the breakpoint, then write this in your immediate window.
new StreamReader(e.Response.GetResponseStream()).ReadToEnd()
You'll then get the details of the HTTP 500 which I hope to give you the answer you're looking for.
Upvotes: 2