Alamofire loading from cache even when cache policy set to ReloadIgnoringLocalAndRemoteCacheData

前端 未结 3 1809
难免孤独
难免孤独 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 23:03

    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.

提交回复
热议问题