I had to manually wire-up my networking layer. To run a query against a web service, I’m using the following code:
public void RunService()
{
string serviceUrl = Constants.URL_OF_SERVICE;
WebRequest request = HttpWebRequest.Create(serviceUrl);
request.BeginGetResponse(new AsyncCallback(Service_Completed), request);
}
private void Service_Completed(IAsyncResult result)
{
try
{
WebRequest request = (WebRequest)(result.AsyncState);
WebResponse response = request.EndGetResponse(result);
// Continue doing stuff
}
catch (WebException ex1)
{
// How do I get the HTTP Status code here?
}
}
I’m having problems getting the HTTP Status Code when an error happens. Can somebody please tell me how to get the HTTP Status code when a WebException is thrown?
Thank you!
Use the
WebResponsewhich is part of theWebException: