objective-c - iOS 5 : https ( ASIHTTPRequest) stop working

标签 objective-c ios5 https asihttprequest ssl

我有一个使用 ASIHTTPRequest 的应用。

使用 iOS 5 重新编译了我的应用 (sdk : 5.0/xcode: 4.2 Build 4D199 ) 并且 https 连接失败 并显示错误消息(同一调用禁用了 https工作正常):

Error Domain=ASIHTTPRequestErrorDomain Code=1 "A connection failure occurred" UserInfo=0xa8e66e0 {NSUnderlyingError=0xa8ac6c0 "The operation couldn’t be completed. (OSStatus error -9844.)", NSLocalizedDescription=A connection failure occurred}

启用调试日志:

[STATUS] Starting asynchronous request <ASIFormDataRequest: 0xd96fc00>

[CONNECTION] Request <ASIFormDataRequest: 0xd96fc00> will not use a persistent connection

[STATUS] Request <ASIFormDataRequest: 0xd96fc00>: Failed

[CONNECTION] Request #(null) failed and will invalidate connection #(null)

我找到了这个相关的帖子: https://devforums.apple.com/message/537440#537440 这可以解释我的问题。

基于 iOS 5 更喜欢 TLS 1.2 的想法,我尝试更改 AIHTTPRequest.m 中的设置 kCFStreamSocketSecurityLevelTLSv1

  NSDictionary *sslProperties = [[NSDictionary alloc] initWithObjectsAndKeys:
                                     [NSNumber numberWithBool:YES],
kCFStreamSSLAllowsExpiredCertificates,
                                     [NSNumber numberWithBool:YES], kCFStreamSSLAllowsAnyRoot,
                                     [NSNumber numberWithBool:NO],  kCFStreamSSLValidatesCertificateChain,
                                     kCFNull,kCFStreamSSLPeerName,
                                      kCFStreamSocketSecurityLevelTLSv1, kCFStreamSSLLevel,// my modif
                                     nil];

没有成功。也许我的修改不正确?

详细信息:

  • 我禁用了 ARC
  • 我使用 libz.1.2.5.dylib
  • 我在一周前更新了 ASIHTTPRequest。

我不知道问题是证书问题(如 TLS 版本)还是其他问题。

欢迎任何帮助/想法!

最佳答案

这是最终的解决方案:

https://developer.apple.com/library/ios/#technotes/tn2287/_index.html#//apple_ref/doc/uid/DTS40011309

        NSDictionary *sslProperties = [[NSDictionary alloc] initWithObjectsAndKeys:
                                       [NSNumber numberWithBool:YES], kCFStreamSSLAllowsExpiredCertificates,
                                       [NSNumber numberWithBool:YES], kCFStreamSSLAllowsAnyRoot,
                                       [NSNumber numberWithBool:NO],  kCFStreamSSLValidatesCertificateChain,
                                       kCFNull,kCFStreamSSLPeerName,
                                       @"kCFStreamSocketSecurityLevelTLSv1_0SSLv3", kCFStreamSSLLevel,
                                       nil];

添加这个参数:

                                       @"kCFStreamSocketSecurityLevelTLSv1_0SSLv3", kCFStreamSSLLevel,

关于objective-c - iOS 5 : https ( ASIHTTPRequest) stop working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7792949/

相关文章:

.net - 使用 WCF (https) 时 WSDL 超链接中的 URL 错误

iphone - 作为 subview 添加到 UINavigationBar 时,UISearchBar 不显示取消按钮

iOS NSDate 和 NSManagedObject

ios - 如何在 iPhone 应用程序的 url 中传递一个字符串值?

ios - iOS 5 ARC 中动态生成的 UIButton 导致释放的实例崩溃

iphone - 我可以在Xcode模拟器中测试加速度计效果吗?

node.js - 如何使用 Lets Encrypt、Node 和 Express 4 设置 HTTPS

ssl - sun.security.validator.ValidatorException : PKIX path building failed: sun. security.provider.certpath.SunCertPathBuilderException: 无法找到

iphone - 我们可以使用相同的 Xib(包含 UIView)来支持横向和纵向吗

Objective-C/ cocoa : Detect all keypresses