Objective-C / Cocoa:如何接受错误的服务器证书? [英] Objective-C/Cocoa: How do I accept a bad server certificate?

查看:162
本文介绍了Objective-C / Cocoa:如何接受错误的服务器证书?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 NSURLRequest ,我尝试访问的证书已过期的网站。当我发送请求时,我的连接:didFailWithError 委托方法调用具有以下信息:

  -1203,NSURLErrorDomain,错误的服务器证书

我的搜索只找到一个解决方案:隐藏类方法在NSURLRequest中:

  [NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:myHost]; 

但是,我不想在生产应用程序中使用私有API。 p>

有什么建议吗?我需要使用CFNetwork API,如果是这样,有两个问题:




  • 我可以使用任何示例代码开始吗?


  • 如果我使用CFNetwork为此,我必须完全抛弃NSURL吗?



    编辑:



    iPhone OS 3.0推出了一种支持的方法。更多详细信息:如何使用NSURLConnection

    iPhone OS 3.0引入了一种支持的方式来执行此操作不需要较低级别的CFNetwork API。更多详细信息:



    如何使用NSURLConnection以SSL连接不受信任的证书?


    Using NSURLRequest, I am trying to access a web site that has an expired certificate. When I send the request, my connection:didFailWithError delegate method is invoked with the following info:

    -1203, NSURLErrorDomain, bad server certificate
    

    My searches have only turned up one solution: a hidden class method in NSURLRequest:

    [NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:myHost];
    

    However, I don't want to use private APIs in a production app for obvious reasons.

    Any suggestions on what to do? Do I need to use CFNetwork APIs, and if so, two questions:

    • Any sample code I can use to get started? I haven't found any online.
    • If I use CFNetwork for this, do I have to ditch NSURL entirely?

    EDIT:

    iPhone OS 3.0 introduced a supported method for doing this. More details here: How to use NSURLConnection to connect with SSL for an untrusted cert?

    解决方案

    iPhone OS 3.0 introduced a supported way of doing this that doesn't require the lower-level CFNetwork APIs. More details here:

    How to use NSURLConnection to connect with SSL for an untrusted cert?

    这篇关于Objective-C / Cocoa:如何接受错误的服务器证书?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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