我正在获得频繁超时错误(并非总是但有时候)但是超时设置为500.邮差也是相同的邮递员两件事邮件连接总是保持活着,第二件是“请求超时”随机出现并不总是.Btt只是在屏幕打开时发生,因为我在ViewDidload中调用了web服务,所以它必须至少等待一段时间。之前抛出错误
这可能是什么原因
以下是我的请求实现
+(void)placeRequest:(NSString *)action parametersString:(NSString*)postDataStr withHandler:(void (^)(NSData *data, NSURLResponse *response, NSError *error))ourBlock {
NSString *urlString = [NSString stringWithFormat:@"%@%@", IOS_BASE_URL, action];
NSURL *url = [NSURL URLWithString:urlString];
NSDictionary *headers = @{ @"content-type": @"application/x-www-form-urlencoded",@"Connection":@"keep-alive", @"cache-control": @"no-cache"};
NSString *parmetersToPost=[NSString stringWithFormat:@"%@%@",postDataStr,[AppDelegate UserWebCommeParmeters] ];
NSMutableData *postData = [[NSMutableData alloc] initWithData:[parmetersToPost dataUsingEncoding:NSUTF8StringEncoding]];
NSString *logString=[NSString stringWithFormat:@"Here the Url is : \n\n\n\n %@ \n\n\n\n\nAction Used is :========> %@ \n\n\n\n\n and the Parmeter posted are :=============> %@",IOS_BASE_URL,action,parmetersToPost];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:500.0];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:postData];
NSLog(@"All header Sent are %@", request.allHTTPHeaderFields);
[[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:ourBlock] resume];
}
在viewdidload中调用此方法,如下所示
[HttpRequest placeRequest:@"check_value" parametersString:postData withHandler:^(NSData *receivedData, NSURLResponse *response, NSError *err){
}];
错误域= NSURLErrorDomain代码= -1001“请求超时。” 的UserInfo = {NSErrorFailingURLStringKey = http://cms.xa.com/apps/xa/ax/myFuntion, _kCFStreamErrorCodeKey = -2102,NSErrorFailingURLKey = http://cms.xa.com/apps/xa/ax/myFuntion, NSLocalizedDescription =请求已超时。 _kCFStreamErrorDomainKey = 4,NSUnderlyingError = 0x16587760 {错误域= kCFErrorDomainCFNetwork代码= -1001“(null)” UserInfo = {_ kCFStreamErrorDomainKey = 4,_kCFStreamErrorCodeKey = -2102}}}