Get the response header of a UIWebView

I looked at ways to get the response header from a UIWebview response. This SO question discusses it. But I'm not sure if this is allowed by an apple. I will have a web view showing the loaded login page and you need to get the response headers after a successful login. Also this

does something to get a status code. But it creates a duplicate NSUrlConnection request. Is there any way I can achieve this? I would appreciate any information on this.

+6
source share
2 answers

In addition to the answer provided by DBD, you need to make sure that

  • containing the UIViewController is marked as UIWebViewDelegate in the .h file:

    @interface VIMAuthenticationViewController : UIViewController <UIWebViewDelegate> 
  • The UIWebView delegate is configured to contain the UIViewController. This can be done directly in the interface building or by linking to a web view, and the addition of the following was uploaded to .m fie:

     [self.WebView setDelegate:self]; 
  • Add the code provided by DBD:

     (void)webViewDidFinishLoad:(UIWebView *)webView { NSCachedURLResponse *resp = [[NSURLCache sharedURLCache] cachedResponseForRequest:webView.request]; NSLog(@"%@",[(NSHTTPURLResponse*)resp.response allHeaderFields]); } 
+11
source

That should do it for you.

 - (void)webViewDidFinishLoad:(UIWebView *)webView { NSCachedURLResponse *resp = [[NSURLCache sharedURLCache] cachedResponseForRequest:webView.request]; NSLog(@"%@",[(NSHTTPURLResponse*)resp.response allHeaderFields]); } 
+8
source

All Articles