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
is a HttpStatusCode
enum, whose underlying integer type is int
, so you can just cast it:
int statusCode = (int)response.StatusCode;