Answer by miniyou for System.Net.WebException HTTP status code
(I do realise the question is old, but it's among the top hits on Google.)A common situation where you want to know the response code is in exception handling. As of C# 7, you can use pattern matching...
View ArticleAnswer by Martin Liversage for System.Net.WebException HTTP status code
By using the null-conditional operator (?.) you can get the HTTP status code with a single line of code: HttpStatusCode? status = (ex.Response as HttpWebResponse)?.StatusCode;The variable status will...
View ArticleAnswer by Sergey for System.Net.WebException HTTP status code
You can try this code to get HTTP status code from WebException. It works in Silverlight too because SL does not have WebExceptionStatus.ProtocolError defined.HttpStatusCode...
View ArticleAnswer by pr0gg3r for System.Net.WebException HTTP status code
this works only if WebResponse is a HttpWebResponse.try{ ...}catch (System.Net.WebException exc){ var webResponse = exc.Response as System.Net.HttpWebResponse; if (webResponse != null &&...
View ArticleAnswer by LukeH for System.Net.WebException HTTP status code
Maybe something like this...try{ // ...}catch (WebException ex){ if (ex.Status == WebExceptionStatus.ProtocolError) { var response = ex.Response as HttpWebResponse; if (response != null) {...
View ArticleAnswer by JaredPar for System.Net.WebException HTTP status code
I'm not sure if there is but if there was such a property it wouldn't be considered reliable. A WebException can be fired for reasons other than HTTP error codes including simple networking errors....
View ArticleSystem.Net.WebException HTTP status code
Is there an easy way to get the HTTP status code from a System.Net.WebException?
View Article