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 ...
随机推荐
- java实现迷宫算法--转
沿着所有方向进行探测,有路径则走,没有路径则从栈中回退. 回溯法是一种不断试探且及时纠正错误的搜索方法,下面的求解过程采用回溯法.从入口出发,按某一方向向前探索,若能走通(未走过的),即某处可以到达, ...
- 虚拟机Linux和Windows之间互传文件的好帮手WinSCP
WinSCP下载地址:http://download.pchome.net/internet/ftp/down-34064-1.html 安装很简单,这里就不做介绍.下面是启动后的界面: 在主机名(H ...
- A SQLite client library written in Modern C++
smartdb是一个纯c++11开发,header-only,简洁高效的sqlite封装库. github地址:https://github.com/chxuan/smartdb,如果您觉得不错,请不 ...
- 关于MFC库和CRT库冲突的分析
当MFC库和CRT库冲突时,会出现一个LNK2005的错误.具体的错误如下: nafxcwd.lib(dllmodul.obj): error LNK2005: _DllMain@12 already ...
- 小白日记50:kali渗透测试之Web渗透-CSRF
CSRF CSRF原理:经常与XSS混淆. 从信任的角度进行区分:XSS:利用用户对站点的信任:CSRF:利用站点对已经身份认证的信任(有一定的信任)[默认情况:站点不信任客户端] 结合社工在身份认证 ...
- Android 之 权限 uses-permission 设置
Manifest.permission 官方API说明: http://developer.android.com/reference/android/Manifest.permission.html ...
- solr查询在solrconfig.xml中的配置
<requestHandler name="/select" class="solr.SearchHandler"> <lst name=&q ...
- 通过继承nsoperation的方法--处理复杂任务
#import <Foundation/Foundation.h> @class TTOperation; @protocol TTOperationDelegate <NSObje ...
- PetaPOCO 一对多 多对一 多对多
PetaPoco支持将结果集中的一行映射到到两个以及更多POCO,但是如何处理一对多和多对多关系? 1.PetaPoco 支持将结果映射为多个POCO类型,提供了另一种方法来处理SQL的Join查询. ...
- [Javascript] 面向对象编程思想
1.创建对象 1.1 new 用new进行创建对象: var user = new Object(); user.age = 12;//同时为对象添加属性 user.name = 'ajun'; 1. ...