0

I am new to iOS and want to call an API for login. I am using Alamofire for HTTP request. I am getting a response from the server but I guess it is saving response in cache. So if I call api with different data is printing same response again. And one more question is I want to save session for later api call. How can I save session data and use it in header for later api call?

This is my Login API Call

let params = ["identity": txtId.text!, "pass": txtPassword.text!]

AF.request(LOGIN_URL, method: .post, parameters: params as Parameters).responseJSON { response in

    print("response = \(response.result.value)")

}
M Reza
  • 18,350
  • 14
  • 66
  • 71
Ajay Gohel
  • 243
  • 7
  • 17

1 Answers1

0

One easy way to remove caches is to call this code before your network call:

URLCache.shared.removeAllCachedResponses()

Or you can also remove caches for a single request:

let urlRequest = URLRequest(url: URL(string: "https://...")!)
URLCache.shared.removeCachedResponse(for: urlRequest)

Then, make your network call:

let params = ["identity": txtId.text!, "pass": txtPassword.text!]

AF.request(LOGIN_URL, method: .post, parameters: params as Parameters).responseJSON { response in
    print("response = \(response.result.value)")
}
M Reza
  • 18,350
  • 14
  • 66
  • 71