SDWebImage and setting custom HTTP headers?

前端 未结 5 733
余生分开走
余生分开走 2020-12-14 18:00

I´ve just changed my code for caching images away from EGOImageCache to SDWebView. Unfortunately i don´t know how to set custom HTTP headers as i have to send authentificati

5条回答
  •  时光说笑
    2020-12-14 18:39

    I had the same problem, and I tried to make:

    SDWebImageDownloader *manager = [SDWebImageDownloader sharedDownloader];
    [manager setValue:username forHTTPHeaderField:@"X-Oauth-Username"];
    

    But the header were not send. After some tries, I came across the problem, SDWebImageDownloader at sharedDownloader makes a new instance of SDWebImageDownloader, so when you put the header at that instance, the instance that really downloads the image don't has the header.

    I've solved making this:

    SDWebImageDownloader *manager = [SDWebImageManager sharedManager].imageDownloader;
    [manager setValue:username forHTTPHeaderField:@"X-Oauth-Username"];
    

提交回复
热议问题