Layer7 API Management

 View Only
  • 1.  Capture Response Headers in iOS (Swift)

    Broadcom Employee
    Posted Sep 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

    Broadcom Employee
    Posted Oct 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)

    Broadcom Employee
    Posted Oct 11, 2018 09:07 AM

    Rodrigo,

     

    This worked. Thanks so much!!