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

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>

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.