I am using the Alamofire networking library in my App to make network requests. At one point I need to make a POST request and add cookies to the request.
How would I do this?
More context:
The cookies I want to send are copied from the response of a GET request that I do before I send the POST request. I store the cookies of the GET requests response in an array of HTTPCookie
.
Searching on internet I found this function
Alamofire.SessionManager.default.session.configuration.httpCookieStorage?.setCookies(cookies, for: response.response?.url, mainDocumentURL: nil)
and the post said that when I make a POST request Alamofire libraries set automatically the cookies. but I try to send a POST request and the cookies aren't in the request. So I check manually if the cookies were saved.
for x in (Alamofire.SessionManager.default.session.configuration.httpCookieStorage?.cookies)! {
print(x)
}
and the methods doesn't print the cookie that I saved with setCookies