获取 UIWebView 响应头 [英] Get UIWebView response header

查看:30
本文介绍了获取 UIWebView 响应头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经研究了从 UIWebview 响应中获取响应标头的方法.这个 SO question 讨论了它.但我不确定苹果是否允许这样做.我将有一个 webview 显示加载的登录页面,并且需要在成功登录后获取响应标头.还有 这个

I have looked into ways to get response header from UIWebview response. This SO question discusses it. But I am unsure if this is allowed by apple. I will have a webview showing a loaded login page and need to get the response headers after a successful login. Also this

做一些事情来获取状态码.但它会创建一个重复的 NSUrlConnection 请求.有什么方法可以实现这一目标吗?如有任何相关信息,我将不胜感激.

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

推荐答案

除了DBD提供的答案,你还需要确保

In addition to the answer provided by DBD, you will need to ensure that

  1. 包含的 UIViewController 在 .h 文件中被标记为 UIWebViewDelegate:

  1. The containing UIViewController is marked as a UIWebViewDelegate in the .h file:

@interface VIMAuthenticationViewController : UIViewController <UIWebViewDelegate>

  • UIWebView 的委托设置为包含 UIViewController.这可以直接在 Interface Building 中完成,也可以通过链接 Web 视图并在 .m fie 中加载的视图中添加以下内容:

  • The UIWebView's delegate is set to the containing UIViewController. This can be done directly in the Interface Building or by linking the web view and adding the following in view did load in .m fie:

    [self.WebView setDelegate:self];
    

  • 添加 DBD 提供的代码:

  • Add the code as provided by DBD:

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

  • 这篇关于获取 UIWebView 响应头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆