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

错误情况

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

猜你喜欢

转载自blog.csdn.net/chabuduoxs/article/details/124562481