How to set Timeout Interval with AFHTTPClient in AFNetworking?

喜你入骨 提交于 2019-12-08 08:59:59

问题


How to set time interval with AFHttpClient

   AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@""]];
    [httpClient setParameterEncoding:AFJSONParameterEncoding];
    [httpClient registerHTTPOperationClass:[AFJSONRequestOperation class]];

回答1:


The time out information is part of the NSURLRequest that you need to create and then feed to the client:

        AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@""]];
    [httpClient setParameterEncoding:AFJSONParameterEncoding];
    [httpClient registerHTTPOperationClass:[AFJSONRequestOperation class]];


    NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:@""] cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:10]; // <- 10 is the timeout interval

    AFHTTPRequestOperation *op = [httpClient HTTPRequestOperationWithRequest:req success:^(AFHTTPRequestOperation *operation, id responseObject) {
        // DONE
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        // FAILED
    }];


来源:https://stackoverflow.com/questions/22666600/how-to-set-timeout-interval-with-afhttpclient-in-afnetworking

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!