iphone项目还必须包含以下文件
ASIAuthenticationDialog.h
ASIAuthenticationDialog.m
添加必要的框架到项目中去 CFNetwork.framework 、SystemConfiguration.framework、libz.1.2.3.dylib
ASIHTTPReques主要特色功能有:
1,下载的数据直接保存到内存或文件系统里
2,提供直接提交(HTTP POST)文件的API
3,可以直接访问与修改HTTP请求与响应HEADER
4,轻松获取上传与下载的进度信息
5,异步请求与队列,自动管理上传与下载队列管理机
6,认证与授权的支持
7,Cookie
8,请求与响应的GZIP
9,代理请求
小例子:
//请求
NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request start];
NSError *error = [request error];
if (!error) {
NSString *response = [request responseString];
}
当你需要添加更多的请求信息时,如,添加个请求Header:
[request addRequestHeader:@"name" value:@"Jory lee"];
添加Post请求时的健值:
[request setPostValue:@"Ben" forKey:@"first_name"];
[request setPostValue:@"Copsey" forKey:@"last_name"];
[request setFile:@"/Users/ben/Desktop/ben.jpg" forKey:@"photo"];
设置HTTP的授权帐号:
[request setUsername:@"username"];
[request setPassword:@"password"];
一个异步请求:
- (IBAction)grabURLInBackground:(id)sender
{
NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
// Use when fetching text data
NSString *responseString = [request responseString];
// Use when fetching binary data
NSData *responseData = [request responseData];
}
- (void)requestFailed:(ASIHTTPRequest *)request
{
NSError *error = [request error];
}