gpt4 book ai didi

ios - CFNetwork SSLHandshake 失败 (-9824) NSURLSession/NSURLConnection HTTP 加载失败 (kCFStreamErrorDomainSSL, -9824)

转载 作者:可可西里 更新时间:2023-11-01 03:31:03 24 4
gpt4 key购买 nike

我在 iOS 9 中使用以下代码向 https 服务器发送发布请求

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

但是我得到以下错误

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

我已经尝试将异常添加到 info.plist 中,如下所示:

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

我也试过

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

它可以在真实设备上运行,但不能在模拟器上运行

最佳答案

  1. From NSURLConnection to NSURLSession worked for me

我能够解决如下问题(不推荐使用 NSURLConnection,您需要使用 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) {
// ...
}];

转换为:

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. 也包含在 Info.plist 中,请参阅文档:

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. 最终

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

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

只需从 api.amazon.com 更改为 yourdomain.net

希望对您有所帮助。

关于ios - CFNetwork SSLHandshake 失败 (-9824) NSURLSession/NSURLConnection HTTP 加载失败 (kCFStreamErrorDomainSSL, -9824),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33276174/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com