AFN拿不到cookie,无法存储cookie

跟雅思的项目对比,发现

task.currentRequest.allHTTPHeaderFields

这样不能拿到cookie

应该这样取:

NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response;
        
        NSDictionary *fileds = response.allHeaderFields;//task.currentRequest.allHTTPHeaderFields;//[operation.response allHeaderFields];
        NSURL *cookieUrl = [NSURL URLWithString:baseUrl];
        NSArray *cookieArray = [NSHTTPCookie cookiesWithResponseHeaderFields:fileds forURL:cookieUrl];

猜你喜欢

转载自www.cnblogs.com/tufei7/p/9634017.html