2011-12-16 58 views
0

在我的應用程序中,我嘗試連接到IIS服務器以訪問某些服務器。 當我運行的應用程序中的iOS 4或更早的連接工作正常,但是當我在iOS 5中運行,連接返回此錯誤:ASIHTTPRequestErrorDomain代碼1

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} 

這是我打電話的代碼:

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]; 

有人有一個想法,爲什麼發生這種情況?

+0

我看到你正在使用ASI。我不確定這個具體的錯誤,但我知道ASIHTTPRequest需要將「libz.dylib」庫作爲iOS 5.0項目依賴關係的一部分。 – Stavash 2011-12-16 20:52:56

回答

5

-9836是一個錯誤的協議錯誤。這可能是由於iOS 5的TLS實現升級到TLS 1.2。如果服務器不支持TLS 1.2,則可能會終止握手並且無法降級到支持的協議級別。

在ASIHTTPRequest.m變化到在下面 - (無效)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); 
    } 

}