获取错误域= NSURLErrorDomain代码= -1012 ios& kCFErrorDomainCFNetwork错误-1012

时间:2014-11-02 09:25:51

标签: ios

尝试使用" 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);
         }
     }];

0 个答案:

没有答案