Search code examples
iosswiftalamofirehttpcookie

How to check which cookies are sent on Alamofire request?


I am using Alamofire for API requests. I need to check which cookies are sent on request.

NetworkService.configuration.httpCookieStorage?.setCookies(cookies, for: try url.asURL(), mainDocumentURL: nil)

I use this for set cookies but i can't see if it is set or not. Is there any way to check this?


Solution

  • You can use the below code to find

    let cookies = HTTPCookie.cookies(withResponseHeaderFields: headerFields, for: URL)
    print(cookies)
    

    OR

    You can use this(View all cookies).

    HTTPCookieStorage.shared.cookies