How can I see the response headers from a WKWebView loadRequest ?
eg
let url = NSURL(string: "http://www.anywebsite.com")!
let urlRequest = NSURLRequest(URL: url)
wkWebView.loadRequest(urlRequest)
then print the headers in the response.
You have to assign wkWebView.navigationDelegate.
In the navigationDelegate's methods that provide a WKNavigationResponse, you can cast navigationResponse.response as a NSHTTPURLResponse to access navigationResponse.response.allHeaderFields.
Swift 5
// MARK: - WKNavigationDelegate
func webView(_ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse) async -> WKNavigationResponsePolicy {
let URLResponse = navigationResponse.response as? HTTPURLResponse
URLResponse?.allHeaderFields.forEach({ key, value in
print("decidePolicyFor key: ", key)
print("decidePolicyFor value: ", value)
})
return .allow
}