2016-11-25 92 views
1

我們拼命嘗試在Swift3中使用Alamofire執行POST請求之前設置cookie。我們只找到Swift2的解決方案。我們當前的代碼看起來像這樣如何設置POST請求的Cookie

Alamofire.request(url, headers: NetworkUtil.getApiKeyHeader()) 
     .responseJSON { response in 
      if let JSON = response.result.value { 
       print("JSON: \(JSON)") 
      } 
     } 

回答

0

它的退出到底簡單,如果你從斯威夫特2

if userCookie != nil, let cookieStorage = Alamofire.SessionManager.default.session.configuration.httpCookieStorage { 
     cookieStorage.setCookies([userCookie!], for: url, mainDocumentURL: nil) 
    } 
適應它