NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813) iOS

前端 未结 4 840
猫巷女王i
猫巷女王i 2020-12-01 17:00

Currently I am consuming a soap web service using block in ios my source code is as follows

NSString *xml = requestXMLToSent;

NSString *msgLength = [NSStrin         


        
相关标签:
4条回答
  • 2020-12-01 17:22

    I assume you use https scheme in your serviceURL and your test server has problems with SSL certificate. If so and you trust it, implement next methods in your NSURLConnection delegate's:

    - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
        return YES;
    }
    
    - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
        if([challenge.protectionSpace.host isEqualToString:@"127.0.0.1"] /*check if this is host you trust: */ )
           [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
    }
    

    To have a delegate initialize your NSURLConnection for example with initWithRequest:delegate:startImmediately: method.

    0 讨论(0)
  • 2020-12-01 17:29

    Check your delegates are actually being called.

    This documentation explains that your delegates may not be getting called in certain circumstances.

    https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/URLLoadingSystem/Articles/AuthenticationChallenges.html

    Important: The URL loading system classes do not call their delegates to handle request challenges unless the server response contains a WWW-Authenticate header. Other authentication types, such as proxy authentication and TLS trust validation do not require this header.

    0 讨论(0)
  • 2020-12-01 17:30

    Server is throwing SSL certificate error. For the sake of testing, you can add the following code to the appDelegate: + (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host { return YES; }

    This will bypass the SSL error

    Note: works for NSURLConnection & UIWebView, but not for WKWebView

    Edited:

    For iOS 9, above procedure don't work. Add the following snippet in info.plist:

    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>
    
    0 讨论(0)
  • 2020-12-01 17:32

    In iOS 9.0 add the following to info.plist

    <key>NSAppTransportSecurity</key>  
         <dict>  
              <key>NSAllowsArbitraryLoads</key><true/>  
         </dict>  
    
    0 讨论(0)
提交回复
热议问题