2012-02-26 36 views
0

我正在使用ASIHttpRequest。我需要知道这个错误信息是什么意思?我怎么能解决这个问题ASIHTTPRequest错误消息 - 初学者

请求错误< ASIHTTPRequest:0xbedc00 > - “出现连接失败” 错误域= ASIHTTPRequestErrorDomain代码= 1的UserInfo = 0x270230 {NSUnderlyingError = 0x250cf0“操作无法完成。 (kCFErrorDomainCFNetwork error 2.)“,NSLocalizedDescription =发生连接失败}

还有更多的错误消息;以上是Error Domain=ASIHTTPRequestErrorDomain Code=1其他是Code=2,Code=3 ...最多Code=10。我需要这些是什么?

编辑: 的误差得到if condition

SBJsonParser *p = [SBJsonParser new];    
     NSDictionary *content = [pobjectWithString:[request responseString]];  
     if(!content){  
      NSLog(@" %@", p.errorTrace); 
      return; 
     } 
+0

你能可以张贴这引起了该错误的代码? – dom 2012-02-26 16:21:27

+0

我已经添加了一个代码。我需要知道这些错误的含义。此外,ASIHTTPRequest发送了10个类似的错误消息。我需要知道他们是什么以及如何处理它。 :S – shajem 2012-02-26 16:28:12

回答

8

中显示此错误意味着主机无法联系,通常是因为你没有网络连接也。

下面是错误代码ASIHTTPRequest.h

typedef enum _ASINetworkErrorType { 
    ASIConnectionFailureErrorType = 1, 
    ASIRequestTimedOutErrorType = 2, 
    ASIAuthenticationErrorType = 3, 
    ASIRequestCancelledErrorType = 4, 
    ASIUnableToCreateRequestErrorType = 5, 
    ASIInternalErrorWhileBuildingRequestType = 6, 
    ASIInternalErrorWhileApplyingCredentialsType = 7, 
    ASIFileManagementError = 8, 
    ASITooMuchRedirectionErrorType = 9, 
    ASIUnhandledExceptionError = 10, 
    ASICompressionError = 11 

} ASINetworkErrorType; 
+0

我想我不能处理这些错误,所以当出现这些错误时,我应该向用户显示哪种错误信息。 – shajem 2012-02-26 16:50:05

+0

显示'[error localizedDescription]',这通常是我所做的。 – 2012-02-26 16:51:05

+0

根据我的代码我怎么能打印这个。当我说content.localizedDescription我得到一个空字符串。 – shajem 2012-02-26 17:03:45

1

定义,你应该尝试这样

-(void)requestFailed:(ASIHTTPRequest *)request{ 

     UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:[request.error localizedDescription] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
     [alertView show]; 
}