【问题标题】:Handling authentication in a UIWebView iOS.How does this work?在 UIWebView iOS 中处理身份验证。这是如何工作的?
【发布时间】:2012-12-26 18:44:33
【问题描述】:

我有一个要求,我必须处理站点的身份验证并将其加载到 UIWebview 中。搜索网络后 因为我创建了一个新的 NSURLConnection 并使用它处理了身份验证挑战(如链接 How to display the Authentication Challenge in UIWebView? 中)

一切正常,但我不明白下面的代码。

- (void)connection:(NSURLConnection *)connection
didReceiveResponse:(NSURLResponse *)response
{

        NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
        NSString *newUrl = [NSString stringWithFormat:@"%@", response.URL];

        // cancel the connection. we got what we want from the response,
        // no need to download the response data.
        [connection cancel];


        //Start loading the new request in webView
        NSURL *url =[NSURL URLWithString:newUrl];
        NSMutableURLRequest *urlRequest=[NSMutableURLRequest requestWithURL:url];

        [webView loadRequest:urlRequest];

}

这里的 webview 只是再次加载请求而不重新发送 cookie 中的任何身份验证信息。然后我明白 iOS 自动处理 cookie 管理。但是当我尝试访问 cookie 并在身份验证后打印它时,它什么也没提供。我使用了以下部分 检索所有 cookie 的代码。

[[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]

那么它是如何工作的呢?

【问题讨论】:

    标签: ios authentication cookies ios-simulator


    【解决方案1】:

    这是当时模拟器的一些问题。我能够在设备上运行应用程序时打印 cookie。

    【讨论】:

      猜你喜欢
      • 2012-02-14
      • 1970-01-01
      • 2022-01-20
      • 2015-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-15
      • 2020-06-11
      相关资源
      最近更新 更多