gpt4 book ai didi

ios - swift如何处理 header 响应navigationAction.request.allHTTPHeaderFields中的多个cookie? ["Set-Cookie"]

转载 作者:行者123 更新时间:2023-11-30 12:58:38 30 4
gpt4 key购买 nike

swift如何处理navigationAction.request.allHTTPHeaderFields?[“Set-Cookie”]。我有一个包含多个 cookie 的响应,我想知道如何处理它,因为 navigationAction.request.allHTTPHeaderFields?["Set-Cookie"] 返回一个字符串。我根本无法对此进行测试,因为我正在尝试实现单点登录,并且我必须等到它部署后才能查看它是否有效。

最佳答案

对于 future 用户来说,以防万一的更好解决方案是实现 WKNavigationDelegate 并迭代 cookie,如下所示:

func webView(_: WKWebView, decidePolicyFor: WKNavigationResponse, decisionHandler: @escaping (WKNavigationResponsePolicy) -> Void) {

let response = (decidePolicyFor.response as! HTTPURLResponse)
let cookies = HTTPCookie.cookies(withResponseHeaderFields: response.allHeaderFields as! [String : String], for: response.url!)

for cookie in cookies {
//cookie.value, cookie.name etc... do logic here
}


decisionHandler(.allow)
}

关于ios - swift如何处理 header 响应navigationAction.request.allHTTPHeaderFields中的多个cookie? ["Set-Cookie"],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40118025/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com