问题
I am using ASIHttpRequest. I need to know what this error message means ? and how could i resolve it
Request error <ASIHTTPRequest: 0xbedc00> -- Error Domain=ASIHTTPRequestErrorDomain Code=1 "A connection failure occurred" UserInfo=0x270230 {NSUnderlyingError=0x250cf0 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error 2.)", NSLocalizedDescription=A connection failure occurred}
There are many more error messages; the above is Error Domain=ASIHTTPRequestErrorDomain Code=1
Other are Code=2
, Code=3
... upto Code=10
. I need to what these are too ?
edit:
The errors gets displayed inside the if condition
SBJsonParser *p = [SBJsonParser new];
NSDictionary *content = [pobjectWithString:[request responseString]];
if(!content){
NSLog(@" %@", p.errorTrace);
return;
}
回答1:
This error means that the host cannot be contacted, most often because you don't have a network connection.
Here are the error codes defined in 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;
回答2:
you should try something like this
-(void)requestFailed:(ASIHTTPRequest *)request{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:[request.error localizedDescription] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alertView show];
}
来源:https://stackoverflow.com/questions/9454609/asihttprequest-error-messages-beginner