2015-10-22 9 views
6

jestem wysłanie żądania POST za pomocą następującego kodu w iOS 9 do serwera httpsCFNetwork SSLHandshake zawiodły (-9824) NSURLSession/NSURLConnection HTTP obciążenie nie powiodło się (kCFStreamErrorDomainSSL, -9824)

[NSURLConnection sendSynchronousRequest:request returningResponse:&requestResponse error:&err]; 

ale pojawia się następujący błąd

CFNetwork SSLHandshake failed (-9824) 
NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9824) 

próbowałem dodanie wyjątku Info.plist następująco:

<key>NSAppTransportSecurity</key> 
<dict> 
    <key>NSExceptionDomains</key> 
    <dict> 
    <key>www.myserver.com</key> 
    <dict> 
    <key>NSIncludesSubdomains</key> 
    <true/> 
    <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key> 
    <true/> 
    <key>NSTemporaryExceptionMinimumTLSVersion</key> 
    <string>TLSv1.1</string> 
</dict> 

Próbowałem też

<key>NSAppTransportSecurity</key> 
    <dict> 
    <key>NSAllowsArbitraryLoads</key> 
    <true/> 
    </dict> 

działa na prawdziwym urządzeniu, ale nie na symulatorze

Odpowiedz

2
  1. Od NSURLConnection do NSURLSession pracował dla mnie

Mogłem rozwiązać jako następujące (NSURLConnection jest przestarzałe i musisz użyć NSURLSession):

NSURL *URL = [NSURL URLWithString:@"http://example.com"]; 
NSURLRequest *request = [NSURLRequest requestWithURL:URL]; 

[NSURLConnection sendAsynchronousRequest:request 
           queue:[NSOperationQueue mainQueue] 
        completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { 
// ... 
}]; 

przekształca się:

NSURL *URL = [NSURL URLWithString:@"http://example.com"]; 
NSURLRequest *request = [NSURLRequest requestWithURL:URL]; 

NSURLSession *session = [NSURLSession sharedSession]; 
NSURLSessionDataTask *task = [session dataTaskWithRequest:request 
            completionHandler: 
^(NSData *data, NSURLResponse *response, NSError *error) { 
    // ... 
    }]; 

[task resume]; 

From NSURLConnection to NSURLSession

  1. Również w Info.plist patrz dokumenty:

Info.plist reference

<key>NSAppTransportSecurity</key> 
<dict> 
    <key>NSExceptionDomains</key> 
    <dict> 
    <key>yourdomain.net</key> 
    <dict> 
    <key>NSIncludesSubdomains</key> 
    <true/> 
    <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key> 
    <true/> 
    <key>NSTemporaryExceptionMinimumTLSVersion</key> 
    <string>1.2</string> 
    <key>NSTemporaryExceptionRequiresForwardSecrecy</key> 
    <false/> 
    </dict> 
    </dict> 
</dict> 
  1. I ostatecznie

Ogłoszenie: CFNetwork SSLHandshake zawiodły (-9824) jednocześnie integrując Zaloguj przez Amazon SDK dla iOS Powrót do kategorii Powrót do kategorii

CFNetwork SSLHandshake failed (-9824) while integrating Login with Amazon SDK for iOS Back to Category Back to Category

Wystarczy zmienić yourdomain.net z api.amazon.com

Mam nadzieję, że to pomaga.

1

Doing następujące rozwiązać mój problem:

  1. dodawać/edytować w informacji.plist

<key>NSAppTransportSecurity</key> <dict> <key>NSExceptionDomains</key> <dict> <key>yourdomain.com</key> <dict> <key>NSIncludesSubdomains</key> <true/> <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key> <true/> <key>NSTemporaryExceptionMinimumTLSVersion</key> <string>1.2</string> <key>NSTemporaryExceptionRequiresForwardSecrecy</key> <false/> </dict> </dict> </dict>

  1. Dodaj następujący kod w swojej klasie, który deleguje NSURLConnection

- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpac { return YES; }

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { 
    NSArray *trustedHosts = [NSArray arrayWithObjects:@"mytrustedhost",nil]; 

    if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]){ 
     if ([trustedHosts containsObject:challenge.protectionSpace.host]) { 
      [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge]; 
     } 
    } 
    [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge]; 
} 

Nadzieja to pomoże.

Powiązane problemy