SDWebImage 加载Https自签名证书时的图片问题
你是否遇到了这种情况,好不容易把自签名HTTPS证书配置好了,访问https接口也成功了,但是图片加载不出来?
传了SDWebImageAllowInvalidSSLCertificates 还是没效果没效果(这种情况只适用于CA我觉得),
并且一直 HTTP load failed (error code: -999 [1:89]),
经过不懈努力,终于找到了在不修改SDWebimageDownloader.m源码的情况下的解决方案;
通过创建SDWebimageDownloader的分类来实现,如下:
.h 文件 1 #import "SDWebImageDownloader.h" 2 3 @interface SDWebImageDownloader (AFNHttps) 4 5 @end
1 #import <SDWebImageDownloader.h> 2 #import "SDWebImageDownloader+AFNHttps.h" 3 4 @implementation SDWebImageDownloader (AFNHttps) 5 6 + (void)load { //设置SDWebImageDownloader的证书 7 [SDWebImageDownloader sharedDownloader].urlCredential = [self myUrlCredential]; 8 } 9 10 + (NSURLCredential *)myUrlCredential { 11 12 NSString *thePath = [[NSBundle mainBundle] pathForResource:@"p12证书名" ofType:@"p12"]; 13 //倒入证书 NSLog(@"thePath===========%@",thePath); 14 NSData *PKCS12Data = [[NSData alloc] initWithContentsOfFile:thePath]; 15 CFDataRef inPKCS12Data = (__bridge CFDataRef)PKCS12Data; 16 17 SecIdentityRef identity = NULL; 18 // extract the ideneity from the certificate 19 [self mosM_extractIdentity:inPKCS12Data toIdentity:&identity]; 20 21 SecCertificateRef certificate = NULL; 22 SecIdentityCopyCertificate (identity, &certificate); 27 28 return [NSURLCredential credentialWithIdentity:identity certificates:nil persistence:NSURLCredentialPersistencePermanent];; 29 } 30 31 32 + (OSStatus)extractIdentity:(CFDataRef)inP12Data toIdentity:(SecIdentityRef*)identity { 33 OSStatus securityError = errSecSuccess; 34 CFStringRef password = CFSTR("p12证书密码"); 35 const void *keys[] = { kSecImportExportPassphrase }; 36 const void *values[] = { password }; 37 CFDictionaryRef options = CFDictionaryCreate(NULL, keys, values, 1, NULL, NULL); 38 CFArrayRef items = CFArrayCreate(NULL, 0, 0, NULL); 39 securityError = SecPKCS12Import(inP12Data, options, &items); 40 if (securityError == 0) 41 { 42 CFDictionaryRef ident = CFArrayGetValueAtIndex(items,0); 43 const void *tempIdentity = NULL; 44 tempIdentity = CFDictionaryGetValue(ident, kSecImportItemIdentity); 45 *identity = (SecIdentityRef)tempIdentity; 46 } 47 if (options) { 48 CFRelease(options); 49 } 50 return securityError; 51 }
转载于:https://www.cnblogs.com/SUPER-F/p/9876522.html
SDWebImage 加载Https自签名证书时的图片问题相关推荐
- 解决ImageLoader加载HTTPS图片证书校验异常问题
解决ImageLoader加载HTTPS图片证书校验异常问题 参考文章: (1)解决ImageLoader加载HTTPS图片证书校验异常问题 (2)https://www.cnblogs.com/cs ...
- UIWebView加载HTTPS
当使用UIWebview加载https的站点时webview总是会报NSURLErrorDomain code=-1202,导致网页加载失败.自己打印错误和网上搜索是因为证书失效,https使用超文本 ...
- UIWebView加载HTTPS站点出现NSURLErrorDomain code=-1202 SSL
最近在做push 信息到facebook中.当使用UIWebview加载https的站点时webview总是会报NSURLErrorDomain code=-1202,导致网页加载失败.自己打印错误和 ...
- 关于使用UIWebView加载HTTPS站点出现NSURLErrorDomain code=-1202
最近在做push 信息到facebook中.当使用UIWebview加载https的站点时webview总是会报NSURLErrorDomain code=-1202,导致网页加载失败.自己打印错误和 ...
- Android WebView 加载https网页白屏,空白解决方案
最近在做一个H5相关的需求,使用WebView加载第三方提供的https网页时显示白屏.但是调试打开Baidu和B站的https网址时就能正常打开.被这个问题困扰了半天. 合作方说是android手机 ...
- 成功解决Glide3.7.0加载https图片,显示占位图问题。
平时我们使用Glide加载http网址的图片的时候,图片可以正常加载出来,但是如果服务器端加上了安全认证,当加载自签名的https图片的时候就会报如下错误(证书路径验证异常). Trust ancho ...
- Glide加载https图片
因为在WWDC 2016开发者大会上,苹果宣布了一个最后期限:到2017年1月1日 App Store中的所有应用都必须启用App Transport Security安全功能,所以受之牵连,因此图片 ...
- 用SDWebImage加载FLAnimatedImage
用SDWebImage加载FLAnimatedImage 效果 源码 https://github.com/YouXianMing/Animations // // GifPictureControl ...
- Android 实现HTTPS自签名证书(非常详细)
1.HTTPS协议 HTTPS协议是由SSL+HTTP协议构建的可进行加密传输.身份认证的网络协议.简单来说, HTTP是超文本传输协议 ,信息是明文传输.SSL 是指安全套接字层,它是一项标准技术, ...
最新文章
- ios wkwebview弹框_iOS WKWebView的javascript alert 不弹的解决方案
- python测试用例怎么写_Python单元测试unittest的具体使用示例
- 解决Spring Boot 整合Security后,所有接口提示Unauthorized、返回401
- boost::mp11::mp_defer相关用法的测试程序
- ssl1007 and ssl -最大乘积 and 加法最大【区间dp练习】
- python中math模块函数_Python常用的一些内建函数和math模块函数
- 物联网项目--基于RFID的智能咖啡馆(Visual Studio+物联网虚拟仿真实验平台)
- 【蓝桥杯嵌入式】【STM32】2_KEYBOARD(主循环扫描+外部中断)
- matlab 取模二和,取模(mod)与取余(rem)的区别——Matlab学习笔记
- 词法分析之LED文件生成程序【调试中......】
- 简述数据可视化制作流程
- 根据3倍图生成2倍图和1倍图
- empty string mysql_Mysql中的null与empty string
- 计算机键盘上的每一个按键编码,键盘按键修理
- 【现代计算机图形学 GAMES101】 第五讲:光栅化(一)
- fiddler更新后证书导出和报错的坑(The root certificate could not be located.)
- CentOS 如何重启iptables防火墙
- JS将秒数换算成具体的天时分秒
- 链队的创建、入队、出队
- Error evaluating expression ‘xxxxx != null and xxxxxx!= ’
热门文章
- 自己的总结(你必须知道的C 495个问题)
- Hbase(3)——desc、alter、时间戳
- iOS Hacker Xcode玩转arm64汇编基础
- 编译错误 无法打开包括文件:“SDKDDKVer.h”: No such file or directory
- java6_64.tar配置_centos6.5_64 java 环境变量配置
- ZAB协议选主过程详解
- c++ primer 5th 练习11.9自己编写的答案
- apex图表使用饼图居中_echarts饼图标题居中以及调整主副标题的间距、字号
- [BUUCTF-pwn]——others_shellcode
- [BUUCTF-pwn]——[OGeek2019]babyrop