22

Here I want to return integer like:

{
    "statusCode": "200"
} 

I am not getting statuscode as a integer.

var response = new HttpResponseMessage();
response.StatusCode = Request.CreateResponse((HttpStatusCode)200;
Vahid Farahmandian
  • 6,081
  • 7
  • 42
  • 62
venkat
  • 231
  • 1
  • 2
  • 8

2 Answers2

41
Console.Write((int)response.StatusCode);

HttpStatusCode (the type of response.StatusCode) is an enumeration where the values of the members match the HTTP status codes, e.g.

public enum HttpStatusCode
{
    ...
    Moved = 301,
    OK = 200,
    Redirect = 302,
    ...
}
user3378165
  • 6,546
  • 17
  • 62
  • 101
6
public int DoHttpOperation(HttpClient client, parameters param)
{
    url = "url which you want to hit";
    client.DefaultRequestHeaders.Add("headername", "headervalue");
    var response = //operation which you want to perfrom GET/PUT/POST/DELETE
    return ((int)response.StatusCode);  //Here you will o/p 
}
Pang
  • 9,564
  • 146
  • 81
  • 122
Sagar
  • 272
  • 1
  • 4
  • 13