HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iPhone发送接收Http请求――ASIHttpRequest大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
ASIhttprequest开源包,封装iPhone/iPad上发送接收http请求,官网地址 http://allseeing-i.com/ASIHTTPRequest/
 
支持功能
1. 下载的数据直接保存到内存或文件系统里
2. 提供直接提交(http POST)文件的API
3. 可以直接访问与修改http请求与响应HEADER
4. 轻松获取上传与下载的进度信息
5. 异步请求与队列,自动管理上传与下载队列管理机
6. 认证与授权的支持
7. Cookie
8. 请求与响应的GZIP
9. 代理请求
 
使用方式:
http://allseeing-i.com/ASIHTTPRequest/Setup-instructions
添加以下文件到项目(若请求只需要哪些文件也可选择添加
ASIhttprequestConfig.h
ASIhttprequestDelegate.h
ASIProgressDelegate.h
ASICacheDelegate.h
ASIhttprequest.h
ASIhttprequest.m
ASIDataCompressor.h
ASIDataCompressor.m
ASIDataDecompressor.h
ASIDataDecompressor.m
ASIFormDatarequest.h
ASIInputStream.h
ASIInputStream.m
ASIFormDatarequest.m
ASINetworkQueue.h
ASINetworkQueue.m
ASIDownloadCache.h
ASIDownloadCache.m
iPhone projects must also include:
ASIAuthenticationDialog.h
ASIAuthenticationDialog.m
Reachability.h (in the External/Reachability folder)
Reachability.m (in the External/Reachability folder)
CFNetwork.framework,
SystemConfiguration.framework,
 MobileCoreservices.framework,
CoreGraphics.framework,
libz.1.2.3.dylib
 

同步请求代码
- (IBACtion)grabURL:(id)sender
{
  nSURL *url = [NSURL URLWithString:@" http://allseeing-i.com"];
  ASIhttprequest *request = [ASIhttprequest requestWithURL:url];
  [request startSynchronous];
  nSError *error = [request error];
  if (!error) {
    nSString *response = [request responseString];
  }
}

异步请求代码
//发起请求,
- (void)newordershowrequest:(NSString *)requesTinfo {
 NSURL *url = [NSURL URLWithString:newordershowLink];
 ASIhttprequest *request = [ASIhttprequest requestWithURL:url];
 //设置处理返回结果代理@L_874_23@,不设置则认为requestFinished
 [request setDidFinishSELEctor:@SELEctor(newordershowrequestFinished:)];
 //设置处理返回错误代理@L_874_23@,不设置则认为requestFailed
 [request setDidFailSELEctor:@SELEctor(newordershowrequestFailed:)]; 
 [request setDelegate:self];
 [request startAsynchronous];
}
//处理返回结果
- (void)newordershowrequestFinished:(ASIhttprequest *)request {
   nSString *responseString = [request responseString];
   nSData *responseData = [request responseData];
}
//处理返回错误
- (void)newordershowrequestFailed:(ASIhttprequest *)request {
 UIAlertView *alert = [[UIAlertView alloc] initWith@R_607_10283@e:@"连接失败" message:@"请检查网络连接." delegate:nil cancelButton@R_607_10283@e:@"确定" otherButton@R_607_10283@es:nil];
 [alert show];
 [alert release];
}
 
通过设置处理返回结果/错误代理@L_874_23@即可处理同时发起的多个请求,如果需要更规范的管理发起的多个请求可以使用队列,代码详见官方例子

大佬总结

以上是大佬教程为你收集整理的iPhone发送接收Http请求――ASIHttpRequest全部内容,希望文章能够帮你解决iPhone发送接收Http请求――ASIHttpRequest所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。