美文网首页
SDWebImage加载图片不显示 报403

SDWebImage加载图片不显示 报403

作者: 小鱼儿喜欢花无缺 | 来源:发表于2017-09-28 15:59 被阅读61次

    图片链接在浏览器中可以显示,但是app中加载不出来。 是因为图片userAgent设置的问题

    NSString *userAgent = @"";
            userAgent = [NSString stringWithFormat:@"%@/%@ (%@; iOS %@; Scale/%0.2f)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleExecutableKey] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleIdentifierKey], [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleVersionKey], [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], [[UIScreen mainScreen] scale]];
            
            if (userAgent) {
                if (![userAgent canBeConvertedToEncoding:NSASCIIStringEncoding]) {
                    NSMutableString *mutableUserAgent = [userAgent mutableCopy];
                    if (CFStringTransform((__bridge CFMutableStringRef)(mutableUserAgent), NULL, (__bridge CFStringRef)@"Any-Latin; Latin-ASCII; [:^ASCII:] Remove", false)) {
                        userAgent = mutableUserAgent;
                    }
                }
                [[SDWebImageDownloader sharedDownloader] setValue:userAgent forHTTPHeaderField:@"User-Agent"];
            }
    

    相关文章

      网友评论

          本文标题:SDWebImage加载图片不显示 报403

          本文链接:https://www.haomeiwen.com/subject/wtqvextx.html