iPhone开发应用ASIFormDataRequest POST操作架构设计
来源:互联网 发布:sendto python buffer 编辑:程序博客网 时间:2024/06/17 20:16
from: http://mobile.51cto.com/iphone-283111.htm
iPhone开发应用中ASIFormDataRequest POST操作架构设计是本文哟啊介绍的内容,主要是来讲述ASIFormDataRequest的POST操作架构设计,方法由自己定义。内容主要是基于代码来实现,来看详细代码。
- //开启iphone网络开关
- [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
- ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURLURLWithString:host]];
- //超时时间
- request.timeOutSeconds = 30;
- //定义异步方法
- [request setDelegate:self];
- [request setDidFailSelector:@selector(requestDidFailed:)];
- [request setDidFinishSelector:@selector(requestDidSuccess:)];
- //用户自定义数据 字典类型 (可选)
- request.userInfo = [NSDictionary dictionaryWithObject:method forKey:@"Method"];
- //post的数据
- [request appendPostData:[body dataUsingEncoding:NSUTF8StringEncoding]];
- //开始执行
- [request startAsynchronous];
- //执行成功
- - (void)requestDidSuccess:(ASIFormDataRequest *)request
- {
- //获取头文件
- NSDictionary *headers = [request responseHeaders];
- //获取http协议执行代码
- NSLog(@"Code:%d",[request responseStatusCode]);
- if ([delegaterespondsToSelector:@selector(OARequestSuccessed:withResponse:WithData:withHeaders:)])
- {
- //执行委托操作 (架构设计 自选)
- [delegate OARequestSuccessed:method withResponse:[request responseString]WithData:[request responseData] withHeaders:headers];
- }
- //清空
- if (request)
- {
- [request release];
- }
- //关闭网络
- [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
- }
- //执行失败
- - (void)requestDidFailed:(ASIFormDataRequest *)request{
- //获取的用户自定义内容
- NSString *method = [request.userInfo objectForKey:@"Method"];
- //获取错误数据
- NSError *error = [request error];
- if ([delegate respondsToSelector:@selector(OARequestFailed:withError:)])
- {
- //执行委托 将错误数据传其他方式(架构设计 自选)
- [delegate OARequestFailed:method withError:error];
- }
- if (request)
- {
- [request release];
- }
- [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
- }
- //执行成功函数
- - (void)OARequestSuccessed:(NSString *)method withResponse:(NSString *)response WithData:(NSData *)data withHeaders:(NSDictionary *)headers
- {
- NSString *responseStr = [[[NSString alloc] initWithData:dataencoding:NSUTF8StringEncoding] autorelease];
- //服务返回post后的数据
- NSLog(@"response:\n%@",responseStr);
- }
- //执行失败函数
- - (void)OARequestFailed:(NSString *)method withError:(NSError *)error
- {
- NSLog(@"Error:%@",error);
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"出错了" message:@"网络连接失败, 请稍后重试."
- delegate:nil cancelButtonTitle:@"好的" otherButtonTitles:nil];
- [alert show];
- [alert release];
- }
小结:iPhone开发应用中ASIFormDataRequest POST操作架构设计的内容介绍完了,希望通过本文的学习能对你有所帮助!
- iPhone开发应用ASIFormDataRequest POST操作架构设计
- IPhone之ASIFormDataRequest POST操作架构设计
- IPhone之ASIFormDataRequest POST操作架构设计
- ASIFormDataRequest POST操作架构设计
- ASIFormDataRequest的POST操作架构设计。
- iPhone开发笔记(11)用ASIFormDataRequest实现图片上传
- iPhone开发笔记(11)用ASIFormDataRequest实现图片上传
- iPhone开发应用UIImage图片对象操作
- 使用ASIFormDataRequest处理post请求
- iPhone 开发之HTTP POST
- iphone开发 http post get
- 6-读书笔记----iOS开发指南:从零基础到App Store上架--iOS-iPhone与iPad应用开发的差异和iOS分层架构设计
- ASIHTTPRequest和ASIFormDataRequest 区别,GET和POST
- ASIHTTPRequest和ASIFormDataRequest 区别,GET和POST
- ASIHTTPRequest和ASIFormDataRequest 区别,GET和POST
- ASIHTTPRequest和ASIFormDataRequest 区别,GET和POST
- iPhone应用设计趋势
- iPhone应用开发——简易计算器的设计
- asp.net Session 保存时间设置
- mysql desc asc基本命令总结
- 小程序——字母大小写转换
- DBMS_XPLAN.DISPLAY_CURSOR v$sql bind-data
- qt参考文档
- iPhone开发应用ASIFormDataRequest POST操作架构设计
- 限制Apache日志文件大小和每天生成日志文件的方法
- 为什么一个java源文件中至多只能有一个public的class声明
- flume 几个比较有用的source、sink和decorator
- 用VS2005写的C++程序能在未安装VS2005的机器上不能直接运行解决
- Visual Studio Express for phone 不能显示控制台的解决方法
- solr中的非英文排序问题解决
- U-Boot for LPC3250
- wamp 在外网(如ip下)访问phpmyadmin