首先介绍下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. 使用sigc++插槽系统

    http://www.cppblog.com/gaimor/archive/2010/02/22/108236.html?opt=admin 我所知的c++插槽系统由3个boost的,sigslot的 ...

  2. IOS 将公历日期转换为中国农历

    代码方法: //日期阳历转换为农历: - (NSString *)convertDateToNongLi:(NSString *)aStrDate { NSDate *dateTemp = nil; ...

  3. oracl 、mysql在线查看文档

    Oracle .mysql在线开发文档: http://www.runoob.com/sql/sql-union.html

  4. Hadoop,HBase集群环境搭建的问题集锦(二)

    10.艾玛, Datanode也启动不了了? 找到log: Caused by: java.net.UnknownHostException: Invalid host name: local hos ...

  5. SVN diff 笔记

    SVN diff命令在实际中经常使用,在此记录使用点滴. #对比工作文件与缓存在.svn的“原始”拷贝: svn diff #显示工作文件和服务器版本2的不同: svn diff -r 2 #显示分支 ...

  6. win10 关闭自动维护计划任务

    重命名 C:\Windows\System32\Tasks\Microsoft\Windows 下的Defrag

  7. 生产服务器环境最小化安装后 Centos 6.5优化配置备忘

    生产服务器环境最小化安装后 Centos 6.5优化配置备忘 作者:Memory 发布于:2014-8-13 15:00 Wednesday 服务器 本文 centos 6.5 优化 的项有18处: ...

  8. Tomcat之配置HTTPS

    1. 在C:\Windows\System32\drivers\etc\hosts文件中新增一条项目web.demo.com,让Tomcat可以通过域名访问: 127.0.0.1 web.demo.c ...

  9. 拯救者14ISK添加ssd6记录

    说起为何,我要安装ssd,拯救者14isk配置也不低,我加了4Gddr4的内存,目前8G内存ddr4/2G独显ddr5显卡GT960/i5-6300处理器.每次开机响应慢,还会出现磁盘100%,很受不 ...

  10. Nginx日志分析利器之GoAccess

    1.介绍GoAccess 是一个用来统计 Apache Web 服务器的访问日志的工具,可即时生成统计报表,速度非常快 查看的统计信息有: 统计概况,流量消耗等 访客排名 动态Web请求 静态web请 ...