0

I have a UIWebView with some static HTML. I want to get the response headers for the img from that html.

code:

let html = "<html><body><img src=\"\(imageUrl)\" alt=\"test\" width=\"70\" height=\"70\"></body></html>"
    webView.loadHTMLString(html, baseURL: nil)

extension ViewController: UIWebViewDelegate {
func webViewDidFinishLoad(_ webView: UIWebView) {
    if let html = webView.stringByEvaluatingJavaScript(from: "document.body.innerHTML") {
        print("html: \(html)")

    }

    print("finish load")

    let res = URLCache.shared.cachedResponse(for: webView.request!)
    print("res: \(res)")
    print("headers: \(res?.response)")
}
}

the cached response is always nil.

Is there a way to get the headers?

Thanks

ilan
  • 4,402
  • 6
  • 40
  • 76

1 Answers1

0

suggest to use NSURLConnection to make the request and extract the the headers field using NSURLResponse. can follow and read this

Community
  • 1
  • 1
jokerday
  • 136
  • 1
  • 10