1. 下载的数据直接保存到内存或文件系统里
2. 提供直接提交(HTTP POST)文件的API
3. 可以直接访问与修改HTTP请求与响应HEADER
4. 轻松获取上传与下载的进度信息
5. 异步请求与队列,自动管理上传与下载队列管理机
6. 认证与授权的支持
7. Cookie
8. 请求与响应的GZIP
9. 代理请求
http://allseeing-i.com/ASIHTTPRequest/Setup-instructions
添加以下文件到项目(若请求只需要哪些文件也可选择添加)
ASIHTTPRequestConfig.h
ASIHTTPRequestDelegate.h
ASIProgressDelegate.h
ASICacheDelegate.h
ASIHTTPRequest.h
ASIHTTPRequest.m
ASIDataCompressor.h
ASIDataCompressor.m
ASIDataDecompressor.h
ASIDataDecompressor.m
ASIFormDataRequest.h
ASIInputStream.h
ASIInputStream.m
ASIFormDataRequest.m
ASINetworkQueue.h
ASINetworkQueue.m
ASIDownloadCache.h
ASIDownloadCache.m
iPhone projects must also include:
ASIAuthenticationDialog.h
ASIAuthenticationDialog.m
Reachability.h (in the External/Reachability folder)
Reachability.m (in the External/Reachability folder)
CFNetwork.framework,
SystemConfiguration.framework,
MobileCoreServices.framework,
CoreGraphics.framework,
libz.1.2.3.dylib
同步请求代码
- (IBAction)grabURL:(id)sender
{
NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request startSynchronous];
NSError *error = [request error];
if (!error) {
NSString *response = [request responseString];
}
}
异步请求代码
//发起请求,
- (void)newOrderShowRequest:(NSString *)requestInfo {
NSURL *url = [NSURL URLWithString:newOrderShowLink];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
//设置处理返回结果代理函数,不设置则默认为requestFinished
[request setDidFinishSelector:@selector(newOrderShowRequestFinished:)];
//设置处理返回错误代理函数,不设置则默认为requestFailed
[request setDidFailSelector:@selector(newOrderShowRequestFailed:)];
[request setDelegate:self];
[request startAsynchronous];
}
//处理返回结果
- (void)newOrderShowRequestFinished:(ASIHTTPRequest *)request {
NSString *responseString = [request responseString];
NSData *responseData = [request responseData];
}
//处理返回错误
- (void)newOrderShowRequestFailed:(ASIHTTPRequest *)request {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"连接失败" message:@"请检查网络连接." delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
[alert show];
[alert release];
}