iOS 解析请求头

2019-03-15  本文已影响0人  索性流年

通常在AFN请求中返回第一个参数便是NSURLSessionTask

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
/** 携带token **/
[manager.requestSerializer setValue:[User_Defaults valueForKey:X_TOTEN] forHTTPHeaderField:@"TOKEN"];
urlStr = [NSString stringWithFormat:@"%@/%@",DOMIAN_NAME,urlStr];
[manager POST:urlStr parameters:parameters progress:^(NSProgress * _Nonnull uploadProgress) {

} success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) 
    [self isTokenExpireWithTask:task]; 
}
failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
}];

//解析请求头返回内容
+(void)isTokenExpireWithTask:(NSURLSessionTask *)task
{
    if ([task.response isKindOfClass:[NSHTTPURLResponse class]])
    {
        NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response;
        NSInteger code = response.statusCode;
        DLog(@"%@",response.allHeaderFields); 
    }
}
上一篇下一篇

猜你喜欢

热点阅读