Skip to content

Instantly share code, notes, and snippets.

@pokk
Created November 18, 2016 00:56
Show Gist options
  • Save pokk/47137f91670a21ef1a184cccc173194f to your computer and use it in GitHub Desktop.
Save pokk/47137f91670a21ef1a184cccc173194f to your computer and use it in GitHub Desktop.
Obtain http header information.

Introduction

We can obtain all of the HTTP header information from WKWebView.

extension ViewController: WKNavigationDelegate, WKUIDelegate {
func webView(_ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse, decisionHandler: @escaping (WKNavigationResponsePolicy) -> Swift.Void) {
let response = navigationResponse.response as! HTTPURLResponse
// Here can get all of the http header infomation after transfer to other view.
self.cookie = response.allHeaderFields["Set-Cookie"] as? String
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment