iPhone发送接收Http请求――ASIHttpRequest

iPhone发送接收Http请求――ASIHttpRequest,第1张

概述ASIHttpRequest开源包,封装iPhone/iPad上发送接收Http请求,官网地址 http://allseeing-i.com/ASIHTTPRequest/   支持功能: 1. 下载的数据直接保存到内存或文件系统里 2. 提供直接提交(HTTP POST)文件的API 3. 可以直接访问与修改HTTP请求与响应HEADER 4. 轻松获取上传与下载的进度信息 5. 异步请求与队列 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   简单示例:
http://allseeing-i.com/ASIHTTPRequest/How-to-use
同步请求代码
- (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];
 //设置处理返回结果代理函数,不设置则默认为requestFinished
 [request setDIDFinishSelector:@selector(newOrderShowRequestFinished:)];
 //设置处理返回错误代理函数,不设置则默认为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_403_5979@:@"连接失败" message:@"请检查网络连接." delegate:nil cancelbutton@R_403_5979@:@"确定" otherbutton@R_403_5979@s:nil];
 [alert show];
 [alert release];
}   通过设置处理返回结果/错误代理函数即可处理同时发起的多个请求,如果需要更规范的管理发起的多个请求可以使用队列,代码详见官方例子 总结

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

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

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1094155.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存