这里我想返回如下的整数:
{
"statusCode": "200"
}
我没有将statuscode
作为整数。
var response = new HttpResponseMessage();
response.StatusCode = Request.CreateResponse((HttpStatusCode)200;
答案 0 :(得分:1)
Console.Write((int)response.StatusCode);
HttpStatusCode(response.StatusCode的类型)是一个枚举,其中成员的值与HTTP状态代码匹配,例如
public enum HttpStatusCode
{
...
Moved = 301,
OK = 200,
Redirect = 302,
...
}
答案 1 :(得分:0)
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
}