ASIHTTPRequestErrorDomain code 1

来源:互联网 发布:打开照片的软件 编辑:程序博客网 时间:2024/05/22 02:19

用域名连,不行。查了下有人解决了:



http://stackoverflow.com/questions/8538449/asihttprequesterrordomain-code-1




0
down votefavorite
1

In my app, i'm trying to connect to a IIS server to access some servers. Whe i run the app in iOS 4 or earlier the connection works fine, but wen i run in iOS 5, the connection retorn this erro:

Error Domain=ASIHTTPRequestErrorDomain Code=1 "A connection failure occurred" UserInfo=0x6b601d0 {NSUnderlyingError=0x6b5fe20 "The operation couldn’t be completed. (OSStatus error -9836.)", NSLocalizedDescription=A connection failure occurred}

this is the code that i call.

self.currentRequest = [ASIHTTPRequest requestWithURL:url];[self.currentRequest setValidatesSecureCertificate:NO];[self.currentRequest setDelegate:self];[self.currentRequest setUsername:credentials.login];[self.currentRequest setPassword:credentials.password];[self.currentRequest setDomain:@"CORP"];[self.currentRequest setUseHTTPVersionOne:YES];[self.currentRequest setTimeOutSeconds:120];[self.currentRequest startAsynchronous];

Samebody have an idea why this is happening?

Thank's

share|improve this question
 
I see you are using ASI. I'm not sure about this specific error, but I do know ASIHTTPRequest needs the "libz.dylib" library to be a part of the project dependencies in iOS 5.0. – Stavash Dec 16 '11 at 20:52
feedback

1 Answer

activeoldestvotes
up vote2down vote

-9836 is a bad protocol error. It's probably due to iOS 5's implementation of TLS being upgraded to TLS 1.2. If TLS 1.2 isn't supported by the server it may terminate the handshake and fail to downgrade to a supported protocol level.

In ASIHTTPRequest.m change to the following in - (void)startRequest

//// Handle SSL certificate settings//if([[[[self url] scheme] lowercaseString] isEqualToString:@"https"]) {           NSDictionary *sslProperties = [[NSDictionary alloc] initWithObjectsAndKeys:                                   @"kCFStreamSocketSecurityLevelTLSv1_0SSLv3", (NSString *)kCFStreamSSLLevel,                                   nil];    CFReadStreamSetProperty((CFReadStreamRef)[self readStream],                             kCFStreamPropertySSLSettings,                             (CFTypeRef)sslProperties);    // Tell CFNetwork not to validate SSL certificates    if (![self validatesSecureCertificate]) {        // see: http://iphonedevelopment.blogspot.com/2010/05/nsstream-tcp-and-ssl.html        NSDictionary *sslProperties = [[NSDictionary alloc] initWithObjectsAndKeys:                                  [NSNumber numberWithBool:YES], kCFStreamSSLAllowsExpiredCertificates,                                  [NSNumber numberWithBool:YES], kCFStreamSSLAllowsAnyRoot,                                  [NSNumber numberWithBool:NO],  kCFStreamSSLValidatesCertificateChain,                                  kCFNull,kCFStreamSSLPeerName,                                  @"kCFStreamSocketSecurityLevelTLSv1_0SSLv3", (NSString *)kCFStreamSSLLevel,                                  nil];        CFReadStreamSetProperty((CFReadStreamRef)[self readStream],                                 kCFStreamPropertySSLSettings,                                 (CFTypeRef)sslProperties);    }    // Tell CFNetwork to use a client certificate    if (clientCertificateIdentity) {        NSMutableDictionary *sslProperties = [NSMutableDictionary dictionaryWithCapacity:2];        NSMutableArray *certificates = [NSMutableArray arrayWithCapacity:[clientCertificates count]+1];        // The first object in the array is our SecIdentityRef        [certificates addObject:(id)clientCertificateIdentity];        // If we've added any additional certificates, add them too        for (id cert in clientCertificates) {            [certificates addObject:cert];        }        [sslProperties setObject:certificates forKey:(NSString *)kCFStreamSSLCertificates];        [sslProperties setObject:@"kCFStreamSocketSecurityLevelTLSv1_0SSLv3" forKey:(NSString *)kCFStreamSSLLevel];        CFReadStreamSetProperty((CFReadStreamRef)[self readStream], kCFStreamPropertySSLSettings, sslProperties);    }}

原创粉丝点击