ASIHttpRequest常用方法

转自:http://blog.csdn.net/richard_rufeng/article/details/14229881


第一、根据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];
 第九 设置超时自动重传
    [httpRequest setNumberOfTimesToRetryOnTimeout:2];
 第十、获取cookies
    NSMutableArray *cookie=[httpRequest requestCookies];
 第十一、清除cookies
    [ASIHTTPRequest clearSession];
 第十二、设置cookie
    [ASIHTTPRequest setSessionCookies:cookie];
 第十三、当前网络是否可用
    [ASIHTTPRequest isNetworkInUse];
 第十四、判断是否为2G/3G
    [ASIHTTPRequest isNetworkReachableViaWWAN];
  第十五、网络请求时,关闭状态显示栏的loading
    [ASIHTTPRequest setShouldUpdateNetworkActivityIndicator:NO];
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值