iPhone开发技巧之私有API(7)--- 用UIWebView访问BASIC认证的页面
来源:互联网 发布:java修改文件名称 编辑:程序博客网 时间:2024/05/16 06:42
比如类似下面的 URL,
1
http://user:password@www.example.com/
需要用户的认证,如果用 UIWebView 访问这样的页面,可以使用下面的委托方法。
1
- (void)webView:(id)fp8 resource:(id)fp12 didReceiveAuthenticationChallenge:(id)fp16 fromDataSource:(id)fp20;
具体参数形式如下。
1234
- (void)webView:(UIWebView *)webView resource:(NSObject *)resource didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge fromDataSource:(WebDataSource *)dataSource;
利用第3个参数—认证的Challenge对象(NSURLAuthenticationChallenge)的 sender 方法,红色纸认证的信息。如果认证失败,可以从NSURLAuthenticationChallenge 的 previousFailureCount 中取得失败的次数。
1234
- (void)webView:(id)webView resource:(id)resource didReceiveAuthenticationChallenge:(id)challenge fromDataSource:(id)dataSource { NSURLCredential *credential = [NSURLCredential credentialWithUser:@"user" password:@"password" persistence:NSURLCredentialPersistenceForSession]; [[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];}
- iPhone开发技巧之私有API(7)--- 用UIWebView访问BASIC认证的页面
- iPhone开发技巧之私有API--- 用UIWebView访问BASIC认证的页面
- 用UIWebView访问BASIC认证的页面
- iPhone开发技巧之私有API(6)--- 设置UIWebView中的User-Agent
- iPhone开发技巧之私有API--- 设置UIWebView中的User-Agent
- iPhone开发技巧之私有API--- UIBarButtonItem
- iPhone开发技巧之私有API--- UISegmentedControl
- iPhone开发技巧之私有API--- UITableView
- iPhone开发技巧之私有API--- UIApplication
- iPhone开发技巧之私有API--- UIBarButtonItem
- iPhone开发技巧之私有API--- UIBarButtonItem
- iPhone开发技巧之私有API
- iPhone开发技巧之私有API--- UIBarButtonItem
- iPhone开发技巧之私有API(2)— UITableView
- iPhone开发技巧之私有API(2)--- UITableView
- iPhone开发技巧之私有API(3)--- UIButton
- iPhone开发技巧之私有API(4)--- UIBarButtonItem
- iPhone开发技巧之私有API(5)--- UISegmentedControl
- 80后程序员的发展路线
- 让Apache日志不记录图片等指定扩展名文件的设置方法
- iPhone开发技巧之私有API(6)--- 设置UIWebView中的User-Agent
- Android学习路线
- 详解如何在postgresql中注入
- iPhone开发技巧之私有API(7)--- 用UIWebView访问BASIC认证的页面
- OGRE实现纸娃娃系统
- iPhone开发技巧之私有API(8)--- UIApplication
- Oracle字符串函数
- android looper 详解
- Oracle 表连接方式分析
- iPhone开发技巧之网络篇(1)--- 解析XML
- Hacking Postgresql for fun!
- DeviceIoControl缓冲模式通信