Search code examples
swiftalamofireswift4

Alamofire - Allow redirecting again


I have POST request where, I had to disallow redirecting - I prevented redirecting with these lines of code:

let delegate = Alamofire.SessionManager.default.delegate
delegate.taskWillPerformHTTPRedirection = {(_, _, _, _) -> URLRequest? in
    return nil
}

In my next POST request I want to allow redirecting, but I don't know how to achieve this. How to allow redirecting, when I prevented redirecting before.


Solution

  • Figured it out:

    // Restore to original behaviour
    let delegate = Alamofire.SessionManager.default.delegate
    delegate.taskWillPerformHTTPRedirection = nil
    

    Thanks to https://nacho4d-nacho4d.blogspot.com/2017/08/preventing-alamofire-redirect.html