NSURLSession "HTTP 加载失败 kCFStreamErrorDomainSSL, -9813 ;自签名证书 [英] NSURLSession "HTTP load failed kCFStreamErrorDomainSSL, -9813 ; Self signing certificate

查看:44
本文介绍了NSURLSession "HTTP 加载失败 kCFStreamErrorDomainSSL, -9813 ;自签名证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的 iOS 应用程序连接到当前在我网络中的本地主机上运行的 HTTPS Rails 应用程序.我可以使用 https://myIP:3000/display 从我的浏览器访问该站点,也可以使用 curl 请求在命令行中访问该站点.我正在尝试使用以下方法从我的应用程序访问它:

class FirstViewController: UIViewController {覆盖 func viewDidLoad() {super.viewDidLoad()//让 url = NSURL(string: "https://another/Sinatra/website/feed")让 url = NSURL(string: "https://myIP:3000/display")让请求 = NSURLRequest(URL: url!)让任务 = NSURLSession.sharedSession().dataTaskWithURL(url!)任务!.resume()}

当我尝试访问 sinatra 网站时,我没有问题,甚至可以使用正确的命令将 JSON 打印到控制台.但是,当我将 url 设置为 Rails 网站时,出现以下错误.

<块引用>

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

此外,我可以看出我的 localhost Rails 应用程序(在另一台机器上)不是从 iOS 应用程序 ping 的,而是从浏览器和 curl 命令 ping 的.

有什么想法可以解决这个问题吗?

解决方案

如果我理解得很好,Apple 现在希望开发人员使用 HTTPS 和 TLS 1.2 进行网络调用.

临时,您可以将其添加到Info.plist"文件中:

NSAppTransportSecurity<字典><key>NSAllowsArbitraryLoads</key><真/></dict>

看看这个链接,它也可以帮助你:

-

否则你可以设置Domain Exceptions.这是怎么做的:

  1. 转到您的 Info.plist 文件.
  2. 添加一行 Type DictionaryKey App Transport Security Settings.
  3. 添加一行 Type DictionaryKey Exception Domains.
  4. 添加一行Type DictionaryKey .
  5. 添加两行 Type BooleanKey NSExceptionAllowsInsecureHTTPLoads &NSIncludesSubdomainsValue 设为 YES.

链接

https://forums.developer.apple.com/message/5857#5857

2015 WWDC 711 会议

iOS 9 HTTP 连接错误 - StackOverflow

I'm trying to connect my iOS app to an HTTPS Rails app which is currently run on a local host in my network. I can access the site from my browser with https://myIP:3000/display as well as in the command line with a curl request. I'm trying to access it from my app using:

class FirstViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //let url = NSURL(string: "https://another/Sinatra/website/feed")
        let url = NSURL(string: "https://myIP:3000/display")

        let request = NSURLRequest(URL: url!)
        let task = NSURLSession.sharedSession().dataTaskWithURL(url!)
        task!.resume()
    }

When I try to access the sinatra website I have no trouble and can even print out the JSON to the console with the correct commands. However, when I set url to my Rails website I get the following error.

NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)

In addition, I can tell that my localhost Rails app (on the other machine) is not pinged from the iOS app, but is pinged from the browser and curl command.

Any ideas how to fix this?

解决方案

If I understood well, Apple now wants the developers to use HTTPS and TLS 1.2 for network calls.

Temporary, you can add this in your "Info.plist" file :

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

Just have a look to this link, it may also help you : http://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/

--

Update : Following some comments the above solution is not anymore working. Here is an updated solution.

  1. Go to your Info.plist file.
  2. Add a row of Type Dictionary and of Key App Transport Security Settings.
  3. In this Dictionary, add a row of Type Boolean, of Key Allow Arbitrary Loads and of Value YES

-

Otherwise you can set Domain Exceptions. This is how to do :

  1. Go to your Info.plist file.
  2. Add a row of Type Dictionary and of Key App Transport Security Settings.
  3. Add a row of Type Dictionary and of Key Exception Domains.
  4. Add a row of Type Dictionary and of Key The domain.
  5. Add two rows of Type Boolean and of Key NSExceptionAllowsInsecureHTTPLoads & NSIncludesSubdomains with Value to YES.

Links

https://forums.developer.apple.com/message/5857#5857

2015 WWDC Session 711

iOS 9 HTTP Connection Error - StackOverflow

这篇关于NSURLSession &quot;HTTP 加载失败 kCFStreamErrorDomainSSL, -9813 ;自签名证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆