I'm getting a System.Net.WebException
saying:
The remote server returned an error: (403) Forbidden.
This is what I'm expecting since invalid headers are being passed in with the http request. However, my code does not seem to be catching the exception like I would expect.
Here is the code:
private void callback(IAsyncResult result)
{
Debug.WriteLine("Callback");
HttpWebResponse response = null;
try
{
response = (result.AsyncState as HttpWebRequest).EndGetResponse(result)
as HttpWebResponse;
}
catch (WebException e)
{
Debug.WriteLine("Exception: " + e);
}
catch (Exception e)
{
Debug.WriteLine("Unknown exception: " + e);
}
}
Why is the exception not caught?