像下面的代码这样获取真累
var totalCount = Convert.ToInt32(response.Headers.GetValues("X-TotalCount").FirstOrDefault());
有没有更简单的方法?比如像Session那样
var totalCount = Session.GetInt32("TotalCount");
自己写了个扩展方法实现了
public static class HttpResponseHeadersExtensions
{
public static int GetInt32(this HttpResponseHeaders headers, string name)
{
return headers.TryGetValues(name, out var values) ?
Convert.ToInt32(values.FirstOrDefault()) : 0;
}
}
使用
var totalCount = response.Headers.GetInt32("X-TotalCount");