将凭据存储到钥匙链
NSURL *url = [NSURL URLWithString:@"http://www.dreamingwish.com/"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setUseKeychainPersistence:YES];
[request setUsername:@"username"];
[request setPassword:@"password"];
将凭据存储到session
[request setUseSessionPersistence:YES];
cookie
清空cookie [ASIHTTPRequest setSessionCookies:nil];
//创建一个cookie
NSDictionary *properties = [[[NSMutableDictionary alloc] init] autorelease];
[properties setValue:[@"Test Value" encodedCookieValue] forKey:NSHTTPCookieValue];
[properties setValue:@"ASIHTTPRequestTestCookie" forKey:NSHTTPCookieName];
[properties setValue:@".dreamingwish.com" forKey:NSHTTPCookieDomain];
[properties setValue:[NSDate dateWithTimeIntervalSinceNow:60*60] forKey:NSHTTPCookieExpires];
[properties setValue:@"/asi-http-request/tests" forKey:NSHTTPCookiePath];
NSHTTPCookie *cookie = [[[NSHTTPCookie alloc] initWithProperties:properties] autorelease];
[request setUseCookiePersistence:NO];
[request setRequestCookies:[NSMutableArray arrayWithObject:cookie]];
客户端证书:
// Will send the certificate attached to the identity (identity is a SecIdentityRef)
[request setClientCertificateIdentity:identity];
// Add an additional certificate (where cert is a SecCertificateRef)
[request setClientCertificates:[NSArray arrayWithObject:(id)cert]];
代理链接 setProxyHost setProxyPort setProxyUsername setProxyPassword setProxyDomain
证书校验 setValidatesSecureCertificate
流量控制
// 这将会对WWAN连接下的request进行流量控制(控制到预定义的值)
// Wi-Fi连接下的 request不会受影响
// 这个方法仅在iOS上可用
[ASIHTTPRequest setShouldThrottleBandwidthForWWAN:YES];
// 这将会对WWAN连接下的request进行流量控制(控制到自定义的值)
// 这个方法仅在iOS上可用
[ASIHTTPRequest throttleBandwidthForWWANUsingLimit:14800];
// 这将会控移动应用(mobile applications)的流量到预定义的值.
// 会限制所有requests, 不管request是不是WiFi连接下的 - <strong>使用时要注意</strong>
[ASIHTTPRequest setMaxBandwidthPerSecond:ASIWWANBandwidthThrottleAmount];
// 记录每秒有多少字节的流量 (过去5秒内的平均值)
NSLog(@"%qi",[ASIHTTPRequest averageBandwidthUsedPerSecond]);
持久链接
[request setRequestMethod:@"PUT"]; [request setShouldAttemptPersistentConnection:YES];
// 设置持久连接的超时时间为120秒
[request setPersistentConnectionTimeoutSeconds:120];
// 彻底禁用持久连接
[request setShouldAttemptPersistentConnection:NO];