This is my code:
HttpWebRequest req = WebRequest.Create(url) as HttpWebRequest;
WebResponse wr = req.GetResponse();
When the server returns 500 Internal Server Error, exception is thrown in req.GetResponse(). I would like the GetResponse() to accept this Response Code, it is normal for the passed url to throw this Response Code. I would like to parse the Html despite Response Code 500 Internal Server Error. Is it possible to say to GetResponse() method not to verify the Response Code?
This can be a php timeout. In such cases, the webserver will return a 500 Internal Server Error. We can fix this error by increasing timeout values or setting other appropriate timeout options so that the remote server will not return a timeout error but wait for the request to be processed.
The HTTP status code 500 is a generic error response. It means that the server encountered an unexpected condition that prevented it from fulfilling the request. This error is usually returned by the server when no other error code is suitable.
The HttpWebRequest class provides support for the properties and methods defined in WebRequest and for additional properties and methods that enable the user to interact directly with servers using HTTP. Do not use the HttpWebRequest constructor.
try
{
HttpWebRequest req = WebRequest.Create(url) as HttpWebRequest;
WebResponse wr = req.GetResponse();
}
catch (WebException wex)
{
var pageContent = new StreamReader(wex.Response.GetResponseStream())
.ReadToEnd();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With