iPhone应用ASIFormDataRequest POST操作架构设计


  本文标签:iPhone ASIFormDataRequest 架构

  iPhone应用ASIFormDataRequest POST操作架构设计是本文要介绍的内容,教你如何学习iphone应用开发架构的设计  。不多说,来看详细内容  。

  //开启iphone网络开关

  1. [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;   
  2. ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURLURLWithString:host]]; 

  //超时时间

  1. request.timeOutSeconds = 30;  

  //定义异步方法

  1. [request setDelegate:self];  
  2. [request setDidFailSelector:@selector(requestDidFailed:)];  
  3. [request setDidFinishSelector:@selector(requestDidSuccess:)];  

  //用户自定义数据   字典类型  (可选)

  1. request.userInfo = [NSDictionary dictionaryWithObject:method forKey:@"Method"]; 

  //post的数据

  1. [request appendPostData:[body dataUsingEncoding:NSUTF8StringEncoding]]; 

  //开始执行

  1. [request startAsynchronous]; 

  //执行成功

  1. - (void)requestDidSuccess:(ASIFormDataRequest *)request  

  //获取头文件

  1. NSDictionary *headers = [request responseHeaders];  

  //获取http协议执行代码

  1. NSLog(@"Code:%d",[request responseStatusCode]);  
  2. if ([delegaterespondsToSelector:@selector(OARequestSuccessed:withResponse:WithData:withHeaders:)])  

  //执行委托操作  (架构设计   自选)

  1. [delegate OARequestSuccessed:method withResponse:[request responseString]WithData:[request responseData] withHeaders:headers];  

  //清空

  1. if (request)  
  2. {  
  3. [request release];  

  //关闭网络

  1. [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;  
  2. }  

  //执行失败

  1. - (void)requestDidFailed:(ASIFormDataRequest *)request{ 

  //获取的用户自定义内容

  1. NSString *method = [request.userInfo objectForKey:@"Method"]; 

  小结:iPhone应用ASIFormDataRequest POST操作架构设计的内容介绍完了,希望通过本文的学习能对你有所帮助!