审核期间游客状态问题(卡了一整天)

 

请求成功之后,存储cookie

- (void)requestGET:(NSString *)URLString
           parames:(id)parames
           success:(void (^)(NSURLSessionDataTask * _Nonnull task, id responseObject))success
           failure:(void (^)(NSURLSessionDataTask * _Nullable task,id error))failure
{
    //AFN没有做UTF8转码 防止URL字符串中含有中文或特殊字符发生崩溃
//    URLString = [[NSString stringWithFormat:@"%@%@",nstrPublicUrl,URLString]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//    [GXHttpDnsHelper changeCookies:URLString andUrl:URLString];
    [self GET:URLString parameters:parames progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if (![UserModel isLogin]) {
            NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response;
            
            NSDictionary *fileds = response.allHeaderFields;
            NSURL *cookieUrl = [NSURL URLWithString:URLString];
            NSArray *cookieArray = [NSHTTPCookie cookiesWithResponseHeaderFields:fileds forURL:cookieUrl];
            [CookieModel saveCookie:cookieArray];
        }
        
        success(task,responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        failure(task,error);
    }];
    
}

 

posted on 2019-07-04 17:19  土匪7  阅读(201)  评论(0编辑  收藏  举报