Итак, мы начали использовать механизм дайджеста в нашем проекте.В VC у меня есть следующий метод:
func imageThumbnailcall() {
self.indicaotrTimer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(self.HandleOverTime), userInfo: nil, repeats: false)
self.backgroundImageTimer = Timer.scheduledTimer(withTimeInterval: 0.09, repeats: true, block: { (timer) in
SDWebImageDownloader.shared().setValue("\(UserDefaults.standard.string(forKey: "imageHeader") ?? "YWRtaW46YWRtaW4=")", forHTTPHeaderField: "Authorization")
SDWebImageDownloader.shared().downloadImage(with:(self.isShowingThermal ? self.thermalUrl : self.visualUrl) as URL, options: [], progress: nil, completed: { (image, data, error, status) in
self.imageLoaderIndicator.stopAnimating()
self.backGroundImageView.image = image
})
})
}
В приведенном выше вызове мне нужно заменить заголовок на дайджест, поэтому я сделал вызов alamofire, получил ошибку 401 и получил это как заголовки:
- some : <NSHTTPURLResponse: 0x1d42265a0> { URL: http://192.168.42.1/images/snapshots/DLTVimage.jpeg } { Status Code: 401, Headers {
Connection = (
"keep-alive"
);
"Content-Length" = (
195
);
"Content-Type" = (
"text/html"
);
Date = (
"Tue, 02 Oct 2018 13:22:25 GMT"
);
"Www-Authenticate" = (
"Digest algorithm=\"MD5\", qop=\"auth\", realm=\"Restricted access\", nonce=\"18f42caa5bb37111\""
);
} }
Я понял, что мне нужно создать строку, подобную этой:
Digest username="admin",realm="Restricted access",nonce="1d382e075bac95ba",uri="/images/snapshots//IRimage.jpeg",response="54c5aad4e9854201c5e66375f41769d2",cnonce="db860bdba0f3f328",algorithm=MD5,qop=auth,nc=00000001"
и использовать ее в качестве заголовка.Hoc я могу сделать это, и есть ли стручок, который может помочь с этим?