var hcHandler = new HttpClientHandler();
//hcHandler.AllowAutoRedirect = false;
var hc = new HttpClient(hcHandler);
hc.DefaultRequestHeaders.Add("user-agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)");
String url = "http://passport.cnblogs.com/login.aspx";
var task = hc.GetAsync(new Uri(url));
HttpResponseMessage response = task.Result;
string statusCode = response.StatusCode.ToString();
I want to get the statusCode in integer, how can I do?
HttpResponseMessage.StatusCode
是一个HttpStatusCode
枚举,它的底层整数类型是int
,所以你可以把它强制转换:
int statusCode = (int)response.StatusCode;
HttpStatusCode
is declared as an enum sort of like:
enum HttpStatusCode
{
NotFound = 404,
...
}
Which means you can do it simply by casting:
int status = (int)HttpStatusCode.NotFound;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.