Alamofire loading from cache even when cache policy set to ReloadIgnoringLocalAndRemoteCacheData

不问归期 提交于 2019-12-03 10:51:07

I'm using this way in a project and it's working:

let mutableURLRequest = NSMutableURLRequest(URL: SERVICEURL)
mutableURLRequest.HTTPMethod = "POST"

mutableURLRequest.HTTPBody = self.createJson()
mutableURLRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
mutableURLRequest.cachePolicy = NSURLRequestCachePolicy.ReloadIgnoringCacheData

request(mutableURLRequest).validate().responseJSON{ response in...

Hope it helps.

Thanks to @FábioSalata I solved my problem like this.

 var req = URLRequest(url: URL(string: "<URL>")!)
 req.httpMethod = "GET"
 req.setValue("application/json", forHTTPHeaderField: "Content-Type")
 req.setValue("<Auth KEY>", forHTTPHeaderField:"Authorization" )
 req.cachePolicy = NSURLRequest.CachePolicy.reloadIgnoringCacheData

 Alamofire.request(req).validate().responseJSON { response in ...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!