21

I'm using the RestSharp HTTP client library for C#.

How I would retrieve the actual numerical http response code? Not only do I not see a property containing the numerical code but I don't even see it in the headers collection.

Howiecamp
  • 2,981
  • 6
  • 38
  • 59

2 Answers2

52

Simply grab the StatusCode property off of the RestResponse object and cast the enum value to int.

RestResponse response = client.Execute(request);
HttpStatusCode statusCode = response.StatusCode;
int numericStatusCode = (int)statusCode;
Pittsburgh DBA
  • 6,672
  • 2
  • 39
  • 68
David L
  • 32,885
  • 8
  • 62
  • 93
  • Terrific. I had failed to realize that IRestResponse.StatusCode (or RestResponse.StatusCode) was of type HttpStatusCode. – Howiecamp Jun 10 '15 at 20:10
-2
Assert.Equal(200, (int)response.StatusCode);
Ru Chern Chong
  • 3,692
  • 13
  • 33
  • 43
Atul
  • 857
  • 8
  • 14