iPhone开发应用ASIHTTPRequest如何获取文件流


  本文标签:iPhone 文件流 ASIHTTPRequest

  iPhone开发应用ASIHTTPRequest如何获取文件流是本文要介绍的内容,主要讲解的是如何获取文件流,内容不多,主要是基于代码来实现文件流的获取,不多说,来看详细代码  。在服务器上获取文件中的内容,此例中的文件为TXT文件

  1. - (void)getContact{  
  2. NSString *host = [[NSUserDefaults standardUserDefaults]objectForKey:@"HOST"];  
  3. ASIHTTPRequest *m_request = [[ASIHTTPRequest alloc]initWithURL:  
  4.    [NSURL URLWithString:[NSStringstringWithFormat:@"%@:8090/contact.txt",host]]];  
  5. [m_request setDelegate:self];  
  6. [m_request setDidFailSelector:@selector(ASIHttpRequestFailed:)];  
  7. [m_request setDidFinishSelector:@selector(ASIHttpRequestSuceed:)];  
  8. [m_request startAsynchronous];  
  9. }  
  10.  
  11. - (void)ASIHttpRequestFailed:(ASIHTTPRequest *)m_request{  
  12. [self hideDial];  
  13. if (m_request) {  
  14. [m_request release];  
  15. }  
  16. }  
  17.  
  18. - (void)ASIHttpRequestSuceed:(ASIHTTPRequest *)m_request{  
  19. NSData *data = [m_request responseData];  
  20.  
  21. if (data)   
  22. {  
  23. NSString *string = [[NSString alloc] initWithData:dataencoding:NSUTF8StringEncoding];  
  24. NSLog(@"%@",string);  
  25. [contact clean];  
  26. if (string)   
  27. {  
  28. [contact storeContacts:string Source:1];  
  29. }  
  30. [string release];  
  31. }  
  32. if (m_request) {  
  33. [m_request release];  
  34.   }

  小结:关于iPhone开发应用ASIHTTPRequest如何获取文件流的内容介绍完了,希望本文对你有所帮助!