首先介绍下AFNetworking中的使用:

2.0要注意个地方:IOS7及其以后,採用AFHTTPSessionManager,IOS7之前採用AFHTTPRequestOperationManager。

以AFHTTPSessionManager为例,代码例如以下:

<span style="font-size:14px;">AFHTTPSessionManager   *httpClient = [AFHTTPSessionManager manager];
httpClient.requestSerializer = [AFHTTPRequestSerializer serializer];
httpClient.responseSerializer = [AFHTTPResponseSerializer serializer]; // SSL Pinning
NSString *certificatePath = [[NSBundle mainBundle] pathForResource:@"certificate" ofType:@"der"];
NSData *certificateData = [NSData dataWithContentsOfFile:certificatePath]; AFSecurityPolicy *securityPolicy = [[AFSecurityPolicy alloc] init];
[securityPolicy setAllowInvalidCertificates:YES];
[securityPolicy setPinnedCertificates:@[certificateData]];
[securityPolicy setSSLPinningMode:AFSSLPinningModeCertificate]; [httpClient setSecurityPolicy:securityPolicy]; [httpClient GET:@"http://xxxx" parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) { } failure:^(NSURLSessionDataTask *task, NSError *error) {
//失败信息
}];</span>

以AFHTTPRequestOperationManager为例,代码例如以下:

<span style="font-size:14px;">AFHTTPRequestOperationManager *httpClient1 = [AFHTTPRequestOperationManager manager];
httpClient1.requestSerializer = [AFHTTPRequestSerializer serializer];
httpClient1.responseSerializer = [AFHTTPResponseSerializer serializer];
// SSL Pinning
NSString *certificatePath1 = [[NSBundle mainBundle] pathForResource:@"certificate" ofType:@"der"];
NSData *certificateData1 = [NSData dataWithContentsOfFile:certificatePath1]; AFSecurityPolicy *securityPolicy1 = [[AFSecurityPolicy alloc] init];
[securityPolicy1 setAllowInvalidCertificates:YES];
[securityPolicy1 setPinnedCertificates:@[certificateData1]];
[securityPolicy1 setSSLPinningMode:AFSSLPinningModeCertificate]; [httpClient setSecurityPolicy:securityPolicy1]; [httpClient1 GET:@"http://xxxx" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
//成功信息
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//失败信息
}];</span>

以下来讲下ASI,

以ASIFormDataRequest为例。代码例如以下:

<span style="font-size:14px;">ASIFormDataRequest * request;
request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@""]];
NSData *cerFile = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"d1" ofType:@"cer"]];
SecCertificateRef cert = SecCertificateCreateWithData(NULL, (__bridge CFDataRef)cerFile);
NSArray *array = [NSArray arrayWithObjects:(__bridge id)cert,nil];
[request setClientCertificates:array];
[request setValidatesSecureCertificate:NO]; [request startSynchronous];</span>

ASIHTTPRequest的參考http://www.tuicool.com/articles/UN3AveR。代码就不贴了。

http://blog.iamzsx.me/show.html?

id=155002

AFNetworking、ASIHTTPRequest中SSL的使用的更多相关文章

  1. ASIHTTPRequest中数据压缩问题与gzip

    出现了类似问题,先mark,以后修改 最近使用asi发现,部分网络回调数据不能正常的json解析,将responseHeaders头打印出来,才发现公司服务器部分数据添加了gzip压缩传输. 最近简单 ...

  2. java中 SSL认证和keystore使用

    java中 SSL认证和keystore使用 2013-10-12 11:08 10488人阅读 评论(0) 收藏 举报   目录(?)[+]     好久没用过SSL认证了,东西久不用,就有点生疏. ...

  3. JAVA中SSL证书认证通讯

    JAVA中SSL证书认证通讯 SSL通讯服务端 /******************************************************************** * 项目名称 ...

  4. AFNetWorking https请求 SSL认证 自制证书

    1.服务器会给一个证书,一般为.pem格式证书 2.将.pem格式的证书转换成.cer格式的证书 打开电脑自带终端 ,进入到桌面  cd Desktop 回车回到桌面Desktop Admin$ 输入 ...

  5. retrofit2中ssl的Trust anchor for certification path not found问题

    在retrofit2中使用ssl,刚刚接触,很可能会出现如下错误. java.security.cert.CertPathValidatorException: Trust anchor for ce ...

  6. 谈Delphi中SSL协议的应用(好多相关文章)

    摘要:本文主要介绍如何在Delphi中使用SSL协议.一共分为七个部分:(1)SSL协议是什么?(2)Delphi中如何使用SSL协议?(3)SSL客户端编程实例.(4)SSL服务端编程实例.(5)S ...

  7. 老陈---谈Delphi中SSL协议的应用[转]

    摘要:本文主要介绍如何在Delphi中使用SSL协议.一共分为七个部分:(1)SSL协议是什么?(2)Delphi中如何使用SSL协议?(3)SSL客户端编程实例.(4)SSL服务端编程实例.(5)S ...

  8. php中ssl开发的若干问题

    最近利用php开发ssl的相关功能,由于第一次做相关的事情,遇到了很多问题,庆幸的是最终都顺利解决了.不过相关的资料很少,都是综合了国内外的相关信息才解决的.现在整理一下,方便后来者遇到问题时解决. ...

  9. 开发微信小程序中SSL协议的申请、证书绑定、TLS 版本处理等

    在上篇随笔<基于微信小程序的系统开发准备工作>介绍了开发微信小程序的一些前期的架构设计.技术路线 .工具准备等方面内容,本篇随笔继续这个步骤,逐步介绍我们实际开发过程中对SSL协议的申请及 ...

随机推荐

  1. redis 配置步骤

    1.下载 2.启动 3.持久化(快照和AOF) 4.主从配置(集群) 5.读写分离 6.自动切换主从 7.哨兵服务(集群) 8.集群锁 9.Session共享

  2. UITabBarController 的配置

    UITabBarController --> UITabBar Customizing Appearance backgroundImage  背景图片 selectedImageTintCol ...

  3. AutoResponder Reference

    Fiddler's AutoResponder tab allows you to return files from your local disk instead of transmitting ...

  4. html 语义化标签拾遗

    1.del和ins标签 兼容性:浏览器全部支持 del:定义文档中已被删除的文本. ins:定义已经被插入文档中的文本. <!DOCTYPE html> <html lang=&qu ...

  5. pushlet单播与多播

    近期要弄一个消息推送的功能,在网上找了非常多的关于pushlet的文章,尽管写的都非常具体,可是本人看了以后却总认为是模棱两可···不知道怎样下手,终于參考了这些文章中的一些内容,并结合官网的源码.做 ...

  6. HDOJ 4699 Editor 栈 模拟

    用两个栈模拟: Editor Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  7. HDUOJ1086You can Solve a Geometry Problem too

    You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/3 ...

  8. HDUOJ---(2203)亲和串

    亲和串 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  9. gVim中重新载入当前文件

    http://club.topsage.com/thread-2251455-1-1.html有些时候当前打开的文件可能被外部程序不知不觉改变了,这个时候我们就需要重新打开这个文件,或是重读/重载一个 ...

  10. Android开发学习之对话框浅析

    对话框式程序运行中弹出的窗口.Android系统中有四种默认的对话框:警告对话框AlertDialog.进度对话框ProgressDialog.日期选择对话框DatePickerDialog以及时间选 ...