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

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

问题描述

我已经研究过从UIWebview响应中获取响应头的方法。
这个问题讨论它。但我不确定苹果是否允许这样做。我将有一个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。这可以直接在界面建设中完成,或者通过链接网页视图并在视图中添加以下内容。在fm中加载:

  • 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天全站免登陆