Есть способ сделать это, используя отражение. Он работает с .NET 4.0. Он обращается к частному полю и может не работать в других версиях .NET без изменений.
Я понятия не имею, почему Microsoft не раскрыла это поле со свойством.
private static int GetStatusCode(WebClient client, out string statusDescription)
{
FieldInfo responseField = client.GetType().GetField("m_WebResponse", BindingFlags.Instance | BindingFlags.NonPublic);
if (responseField != null)
{
HttpWebResponse response = responseField.GetValue(client) as HttpWebResponse;
if (response != null)
{
statusDescription = response.StatusDescription;
return (int)response.StatusCode;
}
}
statusDescription = null;
return 0;
}