Layer7 API Management

Expand all | Collapse all

Capture Response Headers in iOS (Swift)

Jump to Best Answer
  • 1.  Capture Response Headers in iOS (Swift)

    Posted 09-28-2018 02:59 PM

    Is it possible to capture the response headers for iOS? In android, it would look something like the below:

     

    MASUser.login("admin", "password".toCharArray(), new MASCallback<MASUser>() {
    @Override
    public void onSuccess(MASUser result) {
    }

    @Override
    public void onError(Throwable e) {
    ((AuthenticationException)((MASException)e).getRootCause()).getResponse().getHeaders();
    }
    });

     

    But I'm unable to find an equivalent for iOS and the mas.ca.com docs for iOS doesn't highlight this either. Any help would be much appreciated!



  • 2.  Re: Capture Response Headers in iOS (Swift)
    Best Answer

    Posted 10-01-2018 01:41 PM

    Hi there,

     

    in Swift, you can do something like the example below to get the content of the header along with the error:

     

            MASUser.login(withUserName: "admin", password: "password") { (completed, error) in

                if error != nil {

                    let header = (error! as NSError).userInfo["MASResponseInfoHeaderInfoKey"]                

                    print(header!)

                }

            }



  • 3.  Re: Capture Response Headers in iOS (Swift)

    Posted 10-11-2018 09:07 AM

    Rodrigo,

     

    This worked. Thanks so much!!