gpt4 book ai didi

ios - WKWebView session 已过期

转载 作者:行者123 更新时间:2023-12-01 15:50:36 29 4
gpt4 key购买 nike

我有一个在普通网页上工作的 URL,但嵌入在 WKWebView 中,我总是得到错误 session 过期。有什么方法可以在此 WKWebView 上启用 cookie?

最佳答案

您可以从响应中保存 cookie

- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler {
NSDictionary *headers = [(NSHTTPURLResponse *)navigationResponse.response allHeaderFields];
if ([headers objectForKey:@"Set-Cookie"] != nil) {
_cookie = [headers objectForKey:@"Set-Cookie"];
}
decisionHandler(WKNavigationResponsePolicyAllow);
}

并在请求中设置cookie

_request = [[NSMutableURLRequest alloc] initWithURL:url];
[_request setValue:_cookie forHTTPHeaderField:@"Cookie"];
[_webView loadRequest:_request];

关于ios - WKWebView session 已过期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40512939/

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