ASIHttpRequest-创建和执行request
2012-05-11 08:52
483 查看
同步请求
同步请求会在当前线程中执行,使用error属性来检查结束状态(要下载大文件,则需要设定downloadDestinationPath来保存文件到本地):
- (IBAction)grabURLInBackground:(id)sender
{
NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setCompletionBlock:^{
// Use when fetching text data
NSString *responseString = [request responseString];
// Use when fetching binary data
NSData *responseData = [request responseData];
}];
[request setFailedBlock:^{
NSError *error = [request error];
}];
[request startAsynchronous];
}
同步请求会在当前线程中执行,使用error属性来检查结束状态(要下载大文件,则需要设定downloadDestinationPath来保存文件到本地):
; ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; [request startSynchronous]; NSError *error = [request error]; if (!error) { NSString *response = [request responseString]; } }
- (IBAction)grabURLInBackground:(id)sender
{
NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setCompletionBlock:^{
// Use when fetching text data
NSString *responseString = [request responseString];
// Use when fetching binary data
NSData *responseData = [request responseData];
}];
[request setFailedBlock:^{
NSError *error = [request error];
}];
[request startAsynchronous];
}
相关文章推荐
- ASIHttpRequest-创建和执行request
- iOS开发ASIHttpRequest创建和执行request【2】
- iOS开发ASIHttpRequest介绍(一)-- ASIHttpRequest创建和执行request
- ASIHttpRequest-创建和执行request
- iOS开发ASIHttpRequest创建和执行request
- iOS开发ASIHttpRequest创建和执行request
- iOS开发asi使用(一)ASIHttpRequest创建和执行request
- ASIHttpRequest-创建和执行request
- ASIHttpRequest-创建和执行request
- iOS开发ASIHttpRequest创建和执行request
- ios开发之ASIHttpRequest-创建和执行request
- ASIHttpRequest-创建和执行request 的 异步加载和使用块
- ASIHttpRequest-创建和执行request
- ASIHttpRequest-创建和执行request
- ASIHttpRequest-创建和执行request
- ASIHttpRequest的requestFinish代理函数到底在什么线程执行
- ASIHttpRequest:创建队列、下载请求、断点续传、解压缩
- ASIHttpRequest:创建队列、下载请…
- ASIHttpRequest:创建队列、下载请求、断点续传、解压缩
- ASIHttpRequest:创建队列、下载请求、断点续传、解压缩