How to get cookie from a NSURLSession with Swift?

前端 未结 5 604
忘掉有多难
忘掉有多难 2020-12-13 10:04

I have a NSURLSession that calls dataTaskWithRequest in order to send a POST request in this way

func makeRequest(parameters: String, url:String){
    var po         


        
5条回答
  •  我在风中等你
    2020-12-13 10:46

    Swift 3/4, concise solution:

    let cookieName = "MYCOOKIE"
    if let cookie = HTTPCookieStorage.shared.cookies?.first(where: { $0.name == cookieName }) {
        debugPrint("\(cookieName): \(cookie.value)")
    }
    

提交回复
热议问题