I sent request to url1. url1 will redirect to url2 with cookie. url2 is for authorization. And I get code \"302 found\", which is correct. But when url2 redirect back to ur
Another solution worked for me:
Adopt WKNavigationDelegate
, webView.navigationDelegate = self
, then:
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
/// Cancel the navigation action
decisionHandler(.cancel)
/// Navigate yourself
let request = NSMutableURLRequest(url: url)
request.allHTTPHeaderFields = HTTPCookie.requestHeaderFields(with: Auth.getAuthCookies())
webView.load(request as URLRequest)
}
This was all that was needed for my simple case, but I imagine others may also need to copy the other request info that's stored in navigationAction.request
like the navigationAction.request.allHTTPHeaderFields