尝试使用" GET"从服务器提取数据时有时我可以从服务器访问数据,但大多数时候我得到错误域= NSURLErrorDomain Code = -1012
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:20.0f];
[request setHTTPMethod:@"GET"];
[request setHTTPShouldHandleCookies:NO];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:token forHTTPHeaderField:@"X-Auth-Token"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection
sendAsynchronousRequest:request
queue:queue
completionHandler:^(NSURLResponse *response,
NSData *data,
NSError *error) {
if ([data length] >0 && error == nil){
dispatch_async(dispatch_get_main_queue(), ^{
[self loadData:data];
});
}
else if ([data length] == 0 && error == nil){
[HUD hideUIBlockingIndicator];
[CommonModule showAlert:APP_NAME :@" Unable to connect to the server! "];
NSLog(@"Empty Response, not sure why?");
}
else if (error != nil){
[HUD hideUIBlockingIndicator];
[CommonModule showAlert:APP_NAME :@" Unable to connect to the server! "];
NSLog(@"Not again, what is the error = %@", error);
}
}];