分类: iOS平台
2014-03-08 14:39:40
第一、根据url创建请求
ASIHTTPRequest *httpRequest = [ASIHTTPRequest requestWithURL:url];
第二、设置请求的方法
[httpRequest setRequestMethod:@"GET"];
第三、设置最大连接超时时间
[httpRequest setTimeOutSeconds:60];
第四、代理方法表示请求成功
- (void)requestFinished:(ASIHTTPRequest *)request
{
UIImage *image=[UIImage imageWithData:request.responseData];
self.image=image;
}
第五、代理方法表示请求失败
- (void)requestFailed:(ASIHTTPRequest *)request
{
NSError *error=request.error;
NSLog(@"请求出错:%@",error);
}
第六、通过block设置请求失败
[httpRequest setFailedBlock:^{
NSError *error=httpRequest.error;
NSLog(@"请求出 错:%@",error);
}];
第七、通过一个block来实现完成功能回调
[httpRequest setCompletionBlock:^{
[loadingView hide:YES];
第八、ios 4以上,是否开启后台执行
[httpRequest setShouldContinueWhenAppEntersBackground:YES];