ASIHTTPRequest-使用代理连接
来源:互联网 发布:项目数据分析师培训 编辑:程序博客网 时间:2024/05/16 04:31
ASIHTTPRequest检测系统的proxy设置并自动将proxy用于request。从1.0.6版本开始,它还支持PAC文件和要求授权的proxy。
默认情况下,ASIHTTPRequest将尝试自动检测proxy设置。当然,你可以看自己手动设置:
// 手动设置代理服务器NSURL *url = [NSURL URLWithString:@"http://www.dreamingwish.com"];ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];[request setProxyHost:@"192.168.0.1"];[request setProxyPort:3128];// 另一种方法, 使用代理配置脚本文件// (最好使用本地pac文件)[request setPACurl:[NSURL URLWithString:@"path/to/test.pac"]];
要求授权的proxy
在Mac OS上,ASIHTTPRequest可以自动检测到要求授权的proxy的凭据(前提是在系统设定中设置好)。在iOS上,ASIHTTPRequest则无法自动检测出授权凭据,所以你要么手动使用delegate来向你的controller或者用户索取合适的凭据,要么让ASIAuthenticationDialog向用户索取凭据。一旦获得了一个有效的proxy凭据,那么该凭据将被存储到keychian中(前提是启用useKeychainPersistence )并自动重用。
手动为proxy指定凭据
NSURL *url = [NSURL URLWithString:@"http://www.dreamingwish.com"];ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];[request setProxyHost:@"192.168.0.1"];[request setProxyPort:3128];//为要求授权的proxy设置username 和password[request setProxyUsername:@"bencopsey"];[request setProxyPassword:@"password"];// 对于NTLM proxy,还要设置 domain (NTLM proxy功能是未经测试的)[request setProxyDomain:@"la.la.land"];
使用delegate来提供proxy凭据
这个特性的工作原理和“使用delegate提供HTTP授权”一样,只有一点不同:你的delegate要响应proxyAuthenticationNeededForRequest:函数。
使用内建的授权对话框(仅适用于iOS)
这个特性归功于1.0.8版本的新类ASIAuthenticationDialog 。用来向用户索取凭据来授权webserver或者proxy。
如果你的delegate不响应proxyAuthenticationNeededForRequest:函数,那么默认情况下,ASIHTTPRequest将会显示一个对客户来提示用户输入授权凭据。使用ASIHTTPRequest,开发者不再需要写额外的代码来显示授权对话框,因为默认情况下,ASIHTTPRequest就会显示它。
使用同步request时proxy授权对话框不会显示出来。
如果你不限使用proxy授权对话框,那么你要么实现proxyAuthenticationNeededForRequest:,要么设置shouldPresentProxyAuthenticationDialog 为false(此时你的程序将无法连接到proxy)。如果你要改变对话框的样式,你得继承ASIHTTPRequest类,重写showProxyAuthenticationDialog 来显示你自己的对话框或者ASIAuthenticationDialog 子类.
- ASIHTTPRequest-使用代理连接
- ASIHTTPRequest-使用代理连接
- ASIHTTPRequest-使用代理连接
- ASIHTTPRequest-使用代理连接
- 使用ASIHTTPRequest 网络连接
- ASIHTTPRequest 设置Proxy(代理)
- ASIHTTPRequest使用
- ASIHTTPRequest 使用
- ASIHTTPRequest使用
- ASIHTTPRequest使用
- ASIHTTPRequest使用
- ASIHttpRequest 使用
- ASIHTTPRequest使用
- 使用sock5代理连接tcp
- 使用Socket连接穿越CMWAP代理
- 使用Apache 反向代理功能连接 Tomcat
- 使用Apache 反向代理功能连接 Tomcat
- 使用Socket连接穿越CMWAP代理
- 矩阵快速幂--poj3233
- Subsets
- eclipse和myeclipse关联java jar包以及源文件,doc文件
- ASIHTTPRequest-客户端证书支持
- 数据库的事务和锁
- ASIHTTPRequest-使用代理连接
- WebService应用-ABAP实例:ABAP调用外部WebService
- SQL Server使用Merge语句当源表数据集为空时,无法进行查询的问题
- ASIHTTPRequest-其他特性
- Git Diff 输出到文件保留着色
- SQL集合运算 差集 并集 交集
- ASIHTTPRequest-Debug选项
- 用VC写DLL中"error LNK2005: _DllMain@12 already defined"的错误
- AndBug-android调试工具