SDWebImage报错——Error Domain=NSURLErrorDomain Code=-1202

在iOS应用中使用SDWebImage库加载HTTPS头像图片时遇到证书错误,导致无法显示。错误信息表明服务器证书无效,可能带来安全风险。尽管可以将URL的HTTPS改为HTTP来规避问题,但此做法不推荐,因为会牺牲安全性。正确的解决方案应该是修复服务器的SSL证书,确保安全的HTTPS连接。通过修改URL为HTTP暂时解决了图片显示问题。
摘要由CSDN通过智能技术生成

错误情况

NSURL* url = [NSURL URLWithString:_loginModel.data[@"face"]];
        [cell.topImageView sd_setImageWithURL:url placeholderImage:nil completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
            NSLog(@"%@", error);
        }];

这里使用SDWebImage获取自己上传到数据库中的头像,然后无法显示,打印了一下error:
Error Domain=NSURLErrorDomain Code=-1202 “The certificate for this server is invalid. You might be connecting to a server that is pretending to be “cpblog.vip” which could put your confidential information at risk.”
这里的意思就是访问了一个没有证书的私人网站。
打印了一下url :

https://cpblog.vip/shared-parking-dev/2022-05-03/18628556707/401c4691a74c4173ab9c8a85816240a4-20220503215520.png

发现在浏览器是可以访问的,只不过会提示危险,所以我们把url里面的https改成http就可以正常显示了。

 NSMutableString* testString1 = [_loginModel.data[@"face"] mutableCopy];
        [testString1 replaceCharactersInRange:NSMakeRange(0, 5) withString:@"http"];
        NSURL* url = [NSURL URLWithString:testString1];
//        NSURL* url = [NSURL URLWithString:_loginModel.data[@"face"]];
        [cell.topImageView sd_setImageWithURL:url placeholderImage:nil completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
            NSLog(@"%@", error);
        }];
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值