Alamofire loading from cache even when cache policy set to ReloadIgnoringLocalAndRemoteCacheData

前端 未结 3 1799
难免孤独
难免孤独 2021-01-01 22:30

I set cache policy to request in Alamofire to ignore local cache.

Then I load a viewcontroller with network connection, then I disconnect network connection, kill th

3条回答
  •  爱一瞬间的悲伤
    2021-01-01 22:51

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

     var req = URLRequest(url: URL(string: "")!)
     req.httpMethod = "GET"
     req.setValue("application/json", forHTTPHeaderField: "Content-Type")
     req.setValue("", forHTTPHeaderField:"Authorization" )
     req.cachePolicy = NSURLRequest.CachePolicy.reloadIgnoringCacheData
    
     Alamofire.request(req).validate().responseJSON { response in ...
    

提交回复
热议问题