总结一下 第一个项目中的 收获与心得 第一篇 ASIHTTP

用ASIHTTPRequest进行的封装 虽然很简单,没啥东西  但是还是记一下,以后用到更深的可以再更新一下

    ASIHTTPRequest *request = [[ASIHTTPRequest alloc]initWithURL:[NSURL URLWithString:url]];

ASIDownloadCache// 封装HTTP的请求头
    [request addRequestHeader:@"Content-Type" value:@"application/json; charset=UTF-8"];
    [request addRequestHeader:@"Accept" value:@"application/json, text/javascript, */*; q=0.01;version=v2.0"];
    [request addRequestHeader:@"Content-Length" value:[NSString stringWithFormat:@"%d",[url length]]];

//请求包的内容 string 转换UTF8编码
    [request appendPostData:[extraParams dataUsingEncoding:NSUTF8StringEncoding]];
    [request setDelegate:self];

//请求方法 put get post delete
    [request setRequestMethod:aMethod];
    if (type == 0)
    {

// 同步请求  阻塞UI

        [request startSynchronous];
    }
    else
    {

//异步请求

        [request startAsynchronous];
    }

    [request setTimeOutSeconds:120];
    [request setNumberOfTimesToRetryOnTimeout:0];



当设置本地缓存时,Http请求 只能是get 方法如下

//   本地缓存
//    [ASIHTTPRequest
//     setDefaultCache:[ASIDownloadCache sharedCache]];
//    [request setCacheStoragePolicy:ASICacheForSessionDurationCacheStoragePolicy ];
//    [[ASIDownloadCache sharedCache ] setShouldRespectCacheControlHeaders:YES ];
//    [request setSecondsToCache:60*60*24*30];//缓存30天
//    清除本地缓存

 //   [[ASIDownloadCache sharedCache] clearCachedResponsesForStoragePolicy:ASICachePermanentlyCacheStoragePolicy];


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值