1

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

Sankios
  • 183
  • 1
  • 7
  • Welcome to Stack Overflow! I changed the title of your question to be more precise. This helps to attract other developers because it is much more clear to them what you are asking. In that spirit I also changed your question to be more precise. Most of the original text is just _context_ information but not really related to the problem. You should also consider adding code that you tried so far. StackOverflow users do not want to write all of your code. – Jens Apr 11 '17 at 18:10
  • Possible duplicate of [Swift 2.0, Alamofire: Set cookies in HTTP Post Request](http://stackoverflow.com/questions/33083241/swift-2-0-alamofire-set-cookies-in-http-post-request) – Jens Apr 11 '17 at 18:12

0 Answers0