通常在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);
}
}
网友评论