防盗链设置汇总

防盗链

920 发布: 2021/5/21 17:30 本文总阅读量
SDWebimage
SDWebImageDownloader *downloader = [SDWebImageDownloader sharedDownloader];
[downloader setValue:@"你的域名" forHTTPHeaderField:@"Referer"];

YYWebImage
YYWebImageManager *yyImg = [YYWebImageManager sharedManager];
NSMutableDictionary *yy_m_dic = [NSMutableDictionary dictionaryWithDictionary:yyImg.headers];
[yy_m_dic setValue:baserUrl forKey:@"Referer"];
yyImg.headers = [yy_m_dic mutableCopy];

网络下载

NSURL *url = [NSURL URLWithString:href];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSMutableURLRequest *m_reques = [request mutableCopy];
[m_reques addValue:h5url forHTTPHeaderField:@"referer"];
request = [m_reques copy];
ZFPlayer
ZFIJKPlayerManager *playerManager = [[ZFIJKPlayerManager alloc] init];
NSString *ijkRef = [NSString stringWithFormat:@"Referer:%@\r\n",@"你的域名"];
[playerManager.options setFormatOptionValue:ijkRef forKey:@"headers"];
AVPlayer
NSDictionary *header = @{@"Referer":@"你的域名"};
NSURL *url = [NSURL URLWithString:@"http://sksk2.afadd.cn/upload/preview/waichu/waichu.m3u8"];
AVURLAsset *urlAssert = [AVURLAsset URLAssetWithURL:url options:@{@"AVURLAssetHTTPHeaderFieldsKey" : header}];
AVPlayerItem *playItem = [AVPlayerItem playerItemWithAsset:urlAssert];
self.player = [[AVPlayer alloc] initWithPlayerItem:playItem];

JPVideoPlayer【改源文件】
- (void)startDownloadOpeartionWithRequestTask:(JPResourceLoadingRequestWebTask *)requestTask
                                      options:(JPVideoPlayerDownloaderOptions)options {
    if (!self.downloadTimeout) {
        self.downloadTimeout = 15.f;
    }

    // In order to prevent from potential duplicate caching (NSURLCache + JPVideoPlayerCache),
    // we disable the cache for video requests if told otherwise.
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:requestTask.customURL
                                                                cachePolicy:(NSURLRequestReloadIgnoringLocalCacheData)
                                                            timeoutInterval:self.downloadTimeout];
    request.allHTTPHeaderFields = @{@"referer":@"你的域名"}.mutableCopy;

    request.HTTPShouldHandleCookies = (options & JPVideoPlayerDownloaderHandleCookies);
    request.HTTPShouldUsePipelining = YES;
    if (!self.urlCredential && self.username && self.password) {
        self.urlCredential = [NSURLCredential credentialWithUser:self.username
                                                        password:self.password
                                                     persistence:NSURLCredentialPersistenceForSession];
    }
    NSString *rangeValue = JPRangeToHTTPRangeHeader(requestTask.requestRange);
    if (rangeValue) {
        [request setValue:rangeValue forHTTPHeaderField:@"Range"];
    }

    self.runningTask = requestTask;
    requestTask.request = request;
    requestTask.unownedSession = self.session;
    JPDebugLog(@"Downloader 处理完一个请求");
}

SVGAPlayer【改源文件】
- (void)parseWithURL:(nonnull NSURL *)URL
     completionBlock:(void ( ^ _Nonnull )(SVGAVideoEntity * _Nullable videoItem))completionBlock
        failureBlock:(void ( ^ _Nullable)(NSError * _Nullable error))failureBlock {
    NSMutableURLRequest  * request = [NSMutableURLRequest requestWithURL:URL cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:20];
    //rk_Referer
    request.allHTTPHeaderFields = @{@"referer":@"你的域名"};
    [self parseWithURLRequest:request
              completionBlock:completionBlock
                 failureBlock:failureBlock];
}