简体   繁体   English

UIWebview缓慢加载安全页面

[英]UIWebview slow loading secured page

I have a site I'm loading with a UIWebView that has some problems loading when secured with Basic Authtype of Apache: 我有一个网站,我正在加载一个UIWebView,当使用Apache的基本Authtype保护加载时有一些问题加载:

NSString * myUrlAddress = [NSString stringWithFormat:@"http://user:pass@mysite.mydomain.com"];
NSURL *url = [NSURL URLWithString:myUrlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:60.0];
[webView loadRequest:requestObj];

Initial loading works most of the times, but sometimes, especially on reloading of the app the callback 初始加载大部分时间都有效,但有时候,特别是在重新加载应用程序回调时

- (void)webViewDidFinishLoad:(UIWebView *)webViewloc

is not reached, and it is also not running into 没有到达,也没有遇到

-(void)webView:(UIWebView *)wv didFailLoadWithError:(NSError *)error

If I use a different server without .htaccess to secure the page it all works fine. 如果我使用不带.htaccess的其他服务器来保护页面,那么一切正常。

I also see in the access log, that it sometimes just stops loading from the page. 我还在访问日志中看到它有时会停止从页面加载。

Has this something to do with cachePolicy or timeoutInterval ? 这与cachePolicytimeoutInterval吗?

You could try to manage the authentication challenge coming from the server on your own, since it seems that UIWebView is not able to handle it. 您可以尝试自己管理来自服务器的身份验证质询,因为似乎UIWebView无法处理它。

This requires setting up your own NSURLRequest/Connection and handle the challenge in the connection:didReceiveAuthenticationChallenge delegate method before trying to load the actual html page in your UIWebView . 这需要在尝试加载UIWebView的实际html页面之前,设置自己的NSURLRequest / Connection并处理连接中的挑战connection:didReceiveAuthenticationChallenge委托方法。

You can find full sample code here for a GET request. 您可以在此处找到GET请求的完整示例代码 You might also check into a third-party networking framework that makes handling the communication and the challenge easier (eg, ASIHTTPRequest , although it is now in a "frozen" state it works well; or AFNetworking ) 您还可以检查第三方网络框架,以便更轻松地处理通信和挑战(例如, ASIHTTPRequest ,尽管它现在处于“冻结”状态,但它运行良好;或AFNetworking

NSString * myUrlAddress = [NSString stringWithFormat:@"http://user:pass@mysite.mydomain.com"];
NSURL *url = [NSURL URLWithString:myUrlAddress];
[webView loadRequest:[NSURLRequest requestWithURL:url]];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM