【发布时间】: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