IPhone之ASIFormDataRequest POST操作架构设计
来源:互联网 发布:淘宝出售中的商品id 编辑:程序博客网 时间:2024/06/06 00:12
ASIFormDataRequest的POST操作架构设计,方法由自己定义。
//开启iphone网络开关[UIApplication sharedApplication].networkActivityIndicatorVisible = YES; ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString: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 ([delegate respondsToSelector:@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:data encoding: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操作架构设计
- ASIFormDataRequest POST操作架构设计
- ASIFormDataRequest的POST操作架构设计。
- 使用ASIFormDataRequest处理post请求
- ASIHTTPRequest和ASIFormDataRequest 区别,GET和POST
- ASIHTTPRequest和ASIFormDataRequest 区别,GET和POST
- ASIHTTPRequest和ASIFormDataRequest 区别,GET和POST
- ASIHTTPRequest和ASIFormDataRequest 区别,GET和POST
- iPhone 开发之HTTP POST
- iphone之http post数据
- ASIFormDataRequest上传文件之研究
- IPhone之IO操作
- iPhone之文件操作
- ASIFormDataRequest /AFNetworking GET/POST请求的简单封装(block)
- iPhone开发笔记(11)用ASIFormDataRequest实现图片上传
- iPhone开发笔记(11)用ASIFormDataRequest实现图片上传
- setTextFormat与defaultTextFormat的区别
- 将mysql数据库的字段名或表名设为user不可取
- C# 委托实现非控件线程 修改控件对象
- 修改mysql密码 和 添加root用户远程登录权限
- Linux之时钟中断
- IPhone之ASIFormDataRequest POST操作架构设计
- HashMap和Hashtable的区别
- NYOJ 679 The Weight of Tree 搜索+dp+邻接表
- 数据结构--单链表“环”的问题(1)
- 如何用plsql从oracle中导入导出数据
- linux下的IPtables配置
- Oracle EBS Form 开发 Tips
- make menuconfig出现一大堆未定义的错误
- 递归实现二叉树 JAVA