NSURLConnection ignore unverified certificate error when sending a synchronise request
Private API, use with caution.
As we all know, it's easy to ignore the unverified certificate error when we are sending an asynchronise request. We can use the NSURLDelegate method to ignore that error, all we need to do is to override the following method:
- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
[challenge.senderuseCredential:[NSURLCredentialcredentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
}
And there's also a way to ignore the unverified certificate error when we are sending a synchronise request:
Before the @implementation of your http client, you could add the following code:
@interface NSURLRequest (IgnoreSSL)
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString*)host;
@end @implementation NSURLRequest (IgnoreSSL)
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString*)host
{
return YES;
}
@end
This replacement method gets automatically called and you can decide based on the host to allow any certificates or not. Alternatively you can always return YES regardless of the host parameter to ignore all invalid certificates.
Then you would use the following code to get data from the server with an unverified certificate:
NSData* data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSURLConnection ignore unverified certificate error when sending a synchronise request的更多相关文章
- Error when sending message to topic test with key: null, value: 2 bytes with error: (org.apache.kafka.clients.producer.internals.ErrorLoggingCallback)
windows下使用kafka遇到这个问题: Error when sending message to topic test with key: null, value: 2 bytes with ...
- php yii2 使用命令行模式开启脚本 报错 :Error while sending QUERY packet. PID=xxx
背景:使用Yii2命令行模式开启脚本监控rabbitmq队列(或使用nohup &命令后台监控接口),当队列有订单信息,执行查询,更新操作(相当于PHP文件写个查询,更新,使用命令行启动) 问 ...
- code.google.com certificate error: certificate is for www.google.com
有时候我们会碰到下面错误:code.google.com certificate error: certificate is for www.google.com,类似如下: D:\>go ge ...
- Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptabl
在使用AFNetworking 2.0 的时候本来一切很顺畅,但是中途遇到几个比较坑的地方 这里分享一下爬坑经历,忘读者不能速爬坑! 在发送请求后,NSURLSessionDataTask一直报错 ...
- Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html"
2015-11-16 10:39:17.235 PullDemo[338:60b] Application windows are expected to have a root view contr ...
- How to ignore SSL certificate errors in Apache HttpClient 4.4
public static CloseableHttpClient acceptsUntrustedCertsHttpClient() throws KeyStoreException, NoSuch ...
- AFNetworking3.0出现Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable
在发送请求后一直报错, 浏览器解析却没有问题, 所以基本可以确定是AFNetworking的问题 下面是解决方法: AFHTTPSessionManager *manager = [AFHTTPSes ...
- MVC 本地运行可以发布到IIS 报Sorry, an error occurred while processing your request.解决方案
发布MVC程序的时候经常遇到这种情况,每次都要搞好久才找到问题.最终找到解决办法: 报500错误大部分的情况还是程序存在异常,但全部被MVC错误拦截成了友好提示, 只要在Web.config下添加一行 ...
- Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable con
AFHTTPSessionManager * manager = [AFHTTPSessionManager manager]; manager.responseSerializer.acceptab ...
随机推荐
- 激活office 2010
在激活office 2010版本时有的同学可能会用到“mini-KMS_Activator”这个工具,其实这个工具激活成功率并不算高,我就没激活成功.然后就是了另一款自动激活工具“Office 201 ...
- Perl 内部结构详解
PerlGuts Illustrated Version 0.49, for perl 5.20 and older This document is meant to supplement the ...
- 基数树(radix tree)
原文 基数(radix)树 Linux基数树(radix tree)是将指针与long整数键值相关联的机制,它存储有效率,并且可快速查询,用于指针与整数值的映射(如:IDR机制).内存管理等.ID ...
- iOS企业级开发者计划的申请流程
第一步:访问苹果企业版iDP网址:https://developer.apple.com/programs/ios/enterprise/点击Apply Now按钮,开始申请流程. 第二步:点击App ...
- 数据结构【二】:简单阻塞队列BlockingQueue
在POSIX多线程[一]:简单队列simple queue的基础上使用内部互斥锁和条件变量来控制并发以达到线程安全的目的,其主要用于 [生产者-消费者] 队列. 1.BlockingQueue初始化时 ...
- ASP.NET FormsAuthentication跨站点登录时绝对地址返回的问题
关键字:FormsAuthentication, loginUrl, ReturnUrl, AbsoluteUri 在ASP.NET应用程序中,FormsAuthentication几乎是标配,但Fo ...
- DML 数据操纵语言
1.INSERT(插入)语言结构 INSERT INTO table(表名)(要插入的列名) VALUES(要插入的具体值): table:要插入数据的表的表名 column[,column]:表中要 ...
- MyEclipse设置编码方式 转载【http://www.cnblogs.com/susuyu/archive/2012/06/27/2566062.html】
1.windows->Preferences……打开"首选项"对话框,左侧导航树,导航到general->Workspace, 右侧Text file encoding ...
- Java中创建操作文件和文件夹的工具类
Java中创建操作文件和文件夹的工具类 FileUtils.java import java.io.BufferedInputStream; import java.io.BufferedOutput ...
- Flume与Kafka集成
一.Flume介绍 Flume是一个分布式.可靠.和高可用的海量日志聚合的系统,支持在系统中定制各类数据发送方,用于收集数据:同时,Flume提供对数据进行简单处理,并写到各种数据接受方(可定制)的能 ...