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];

最新文章

  1. Sanarus公司的Cassi微创乳房活检设备投入使用
  2. 51nod比赛
  3. 3 构建Mysql+heartbeat+DRBD+LVS集群应用系统系列之heartbeat的搭建
  4. 【POJ3237】Tree 树链剖分+线段树
  5. 认识Runtime2
  6. java 14-3 正则表达式的分割
  7. LeetCode Subsets II (DFS)
  8. JDBC数据库连接池原理
  9. Linux kmalloc/kfree 源码解读
  10. 【BZOJ [1878】[SDOI2009]HH的项链
  11. 3 委托、匿名函数、lambda表达式
  12. HTML5 ArrayBuffer:类型化数组 (二)
  13. UWP:使用Behavior实现FlipView简单缩放效果
  14. Node.js Web 模块
  15. webpack + babel
  16. 【原创】canvas裁剪上传图片异步提交
  17. 3.Zuul-过滤器
  18. 【题解】JSOIWC2019 Round1
  19. LeetCode 49 Group Anagrams(字符串分组)
  20. label语句、break语句和continue语句

热门文章

  1. linux 文件系统的管理 (硬盘) 工作原理
  2. mysql数据类型区别
  3. BootStrap2学习日记20---定制缩略图
  4. 基于http协议的api接口对于客户端的身份认证方式以及安全措施
  5. 【python,logging】python中的logging模块
  6. Linux中的特殊权限粘滞位(sticky bit)详解
  7. selenium遍历控件集合
  8. oc中的分类/协议/属性
  9. Unity之读取本地图片
  10. SQL跨服务器操作语句