Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# how create WebException with Response status code

Tags:

I make some fake class, that should have same behavior as original one. Original class sometimes throws WebExceptions (with StatusCode in response from server).

I want repeat this behavior without any connection. So, how can i create new WebException(..., ..., ..., ...) with needed StatusCode

like image 755
murzagurskiy Avatar asked Jul 21 '16 07:07

murzagurskiy


1 Answers

You need to customize a class to increase the HTTP Status Code:

public class HttpWebException : WebException
{
    public int HttpStatusCode { get; set; }        
}
like image 137
Fan TianYi Avatar answered Oct 11 '22 10:10

Fan TianYi