我有一个使用 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 版本)还是其他问题。
欢迎任何帮助/想法!
最佳答案
这是最终的解决方案:
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/