0
로그인 응용 프로그램을 작성 중입니다. 성공적으로 로그인 한 후 쿠키가 2 개 나오면 HTTPURLResponse 헤더에서이 2 개의 쿠키를 가져오고 싶습니다. (httpResponse fields didn ' 쿠키가 포함되어 있습니다.) 앞으로 요청할 때 어떻게 찾을 수 있습니까? 나에게 도움을 주셔서 감사합니다 내 일부 코드 쿠키를 HTTPURLResponse에서 저장하는 방법
: 불행하게도 같은let task = URLSession.shared.dataTask(with: request) { data, response, error in
if let httpResponse = response as? HTTPURLResponse, let fields = httpResponse.allHeaderFields as? [String : String] {
let cookies = HTTPCookie.cookies(withResponseHeaderFields: fields, for: (response?.url!)!)
for cookie in cookies {
//print ("hi")
var cookieProperties = [HTTPCookiePropertyKey: Any]()
cookieProperties[HTTPCookiePropertyKey.name] = cookie.name
cookieProperties[HTTPCookiePropertyKey.value] = cookie.value
cookieProperties[HTTPCookiePropertyKey.domain] = cookie.domain
cookieProperties[HTTPCookiePropertyKey.path] = cookie.path
cookieProperties[HTTPCookiePropertyKey.version] = NSNumber(value: cookie.version)
cookieProperties[HTTPCookiePropertyKey.expires] = cookie.expiresDate
let newCookie = HTTPCookie(properties: cookieProperties)
HTTPCookieStorage.shared.setCookie(newCookie!)
} }
}
task.resume()
내가 그것을 시도했지만, 스위프트 3 롭을 사용하여 메신저 신속이 사용하고 나를 위해 작동하지 않았다 아니다 –