ASIHTTPRequest访问https[error-9844]解决方法

iOS 终端请求服务端数据时,为了保证数据安全,我们一般会使用https协议加密,而对于iOS的网络编程,我们一般会使用开源框架:ASIHTTPRequest,但是如果使用传统的http方式,即使忽略验证的话,程序也会报[error-9844]的错误,具体错误如下描述:

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

那么该如何解决该问题呢?经过查找解决方案如下:

解决方案1

1) [request setValidatesSecureCertificate:NO];

2) ASIHTTPRequest.m文件中查找”https”,sslProperties字典中增加kCFStreamSSLLevel对象,网上的参考方法:

[sslProperties setObject:(NSString *)(CFStringRef*)kCFStreamSocketSecurityLevelSSLv3 forKey:(NSString*)kCFStreamSSLLevel];

但是,sslProperties字典并非可变字典,所以你需要将sslProperties修改为可变字典NSMutableDictionary

解决方案2

如果需要更加灵活的对SSL security level进行设置,可以将CFStringRef*sslSecurityLevel作为变量提到ASIHTTPRequest.h文件的property中,具体操作如下:

1) ASIHTTPRequest.h的文件中添加声明:

CFStringRef *sslSecurityLevel;

2) ASIHTTPRequest.h的文件中添加CFStringRef属性:

@property (assign) CFStringRef *sslSecurityLevel;

3) ASIHTTPRequest.m的文件中添加CFStringRef属性:

@synthesize sslSecurityLevel;

4) ASIHTTPRequest.m的文件修改:

NSDictionary *sslProperties = [[NSDictionary alloc]initWithObjectsAndKeys:??,将不可变字典更改为可变字典(NSMutableDictionary),即:

NSMutableDictionary *sslProperties = [[NSMutableDictionary alloc]initWithObjectsAndKeys:??

5) 4)修改语句结束的地方添加设置SSL security level的代码:

// Use requested SSL security level

if ([self sslSecurityLevel] != nil) {

[sslProperties setObject:(NSString *)[self sslSecurityLevel] forKey:(NSString *)kCFStreamSSLLevel];

}

6) 在调用请求的request中做如下设置:

[request setValidatesSecureCertificate:NO];

[request setSslSecurityLevel:(CFStringRef*)kCFStreamSocketSecurityLevelSSLv3];




转自:http://mmz06.blog.163.com/blog/static/12141696201211752931454/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值