Ios NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9813)

Ios NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9813),ios,objective-c,xcode7.2,Ios,Objective C,Xcode7.2,当我使用http://domain.com。但是今天,当我将http://更改为https://时,我面临着这个问题:NSURLSession/NSURLConnection http加载失败(kcfstreamerordomainssl,-9813)。我还在.plist中进行了更改。这是我的.plist代码: <key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArb

当我使用
http://domain.com
。但是今天,当我将
http://
更改为
https://
时,我面临着这个问题:
NSURLSession/NSURLConnection http加载失败(kcfstreamerordomainssl,-9813)
。我还在
.plist
中进行了更改。这是我的
.plist
代码:

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
        <key>NSExceptionDomains</key>
        <dict>
            <key>dev.domainName.in</key>
            <dict>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSTemporaryExceptionMinimumTLSVersion</key>
                <string>TLSv1.2</string>
            </dict>
        </dict>
    </dict>
NSAppTransportSecurity
NSAllowsArbitraryLoads
NSExceptionDomains
dev.domainName.in
N异常低安全Http负载
n包括多个域
NSTemporaryExceptionMinimumTLSVersion
TLSv1.2

但我仍然面临着这个问题。请帮帮我。我错过了什么?

从iOS 9开始,苹果已经实施了ATS。这是有关的文件。试着放松限制,看看它是否有效


它是否适用于运行iOS 9之前的OS版本的设备?

根据您的评论,您收到了一个无效的证书错误,并且正在使用NSURLConnection,您的解决方案是实现这些委托。看看这是否解决了问题

-(void)连接:(NSURLConnection*)连接将发送RequestForAuthenticationChallenge:(nsurAuthenticationChallenge*)质询{
[challenge.sender useCredential:[NSURLCredential Credential-ForTrust:challenge.protectionSpace.serverTrust]
验证质询:质询];
}

请注意,您基本上忽略SSL错误并允许连接继续。因此,如果你打开应用程序进行黑客攻击。对于测试,您可以使用它,但请确保在生产环境中安装了正确的证书

但是,如果您想正确处理此问题,并在证书不正确时警告用户,您可以这样做

OSStatus err = noErr;
BOOL trusted = NO;
NSURLProtectionSpace *  protectionSpace = challenge.protectionSpace;
SecTrustRef serverTrustRef = protectionSpace.serverTrust;
SecTrustResultType trustResult;

//check if the server trust that we got from the server can be trusted by default
err = SecTrustEvaluate(serverTrustRef, &trustResult);
trusted = (err == noErr) && ((trustResult == kSecTrustResultProceed) || (trustResult == kSecTrustResultUnspecified));

if (trusted) //if the site is trusted then continue with that trust
{
    [challenge.sender useCredential:[NSURLCredential credentialForTrust:protectionSpace.serverTrust]
          forAuthenticationChallenge:challenge];
}
else //if not then warn the user about this and let the user make a decision
{
    //warn the user about the cert problem using a dialog with options to continue or ignore.
   //Continue alert action call : [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]
          forAuthenticationChallenge:challenge];
   //Dont continue action: [challenge.sender continueWithoutCredentialForAuthenticationChallenge:_challenge]; 
   //OR call: [sender cancelAuthenticationChallenge:challenge];
}

}

您可以使用设备的浏览器调用同一URL吗?这给了我一个错误:无法验证服务器标识您是在web视图中打开此URL,还是使用它使用NSURLSession或NSURLConnection类进行网络api调用?如果你同意的话,你介意分享完整的url吗?似乎您需要处理身份验证挑战,因为您看到的错误是由未识别的证书引起的。在这种情况下,您必须实现在连接期间调用的某些委托方法,并相应地处理它们。我使用的是NSURLConnection类。我已经阅读了此文档,并使用了它们提供的代码。但它仍然给了我一个错误。请尝试使用此站点检查您的证书是否存在任何问题。证书是自签名的。用户访问此网站时将收到警告,除非该证书作为受信任的证书手动添加到其web浏览器中。您可以通过购买受信任的SSL证书来修复此错误,这就是问题所在。您必须使用自签名证书。您应该从证书颁发机构购买SSL证书。您还可以将其添加到设备的根证书列表中。但是,您必须自己管理证书的分发。我建议您购买SSL证书。如何将其添加到设备的根证书列表?我应该在哪里编写此代码?在您的NSURLConnectionLegate中。放置一些NSLog调用,查看控件是否也用于参考。未调用委托。必须将委托设置为NSURLConnection对象。它可以是您的控制器,也可以是从中调用NSURLConnection方法的单独对象在UIViewController中,我使用以下代码:[NSURLConnection sendAsynchronousRequest:请求队列:[NSOperationQueue mainQueue]completionHandler:^(NSURLResponse*响应,NSData*数据,NSError*连接错误){