iPhone开发应用ASIHTTPRequest如何获取文件流是本文要介绍的内容,主要讲解的是如何获取文件流,内容不多,主要是基于代码来实现文件流的获取,不多说,来看详细代码。在服务器上获取文件中的内容,此例中的文件为TXT文件
- - (void)getContact{
- NSString *host = [[NSUserDefaults standardUserDefaults]objectForKey:@"HOST"];
- ASIHTTPRequest *m_request = [[ASIHTTPRequest alloc]initWithURL:
- [NSURL URLWithString:[NSStringstringWithFormat:@"%@:8090/contact.txt",host]]];
- [m_request setDelegate:self];
- [m_request setDidFailSelector:@selector(ASIHttpRequestFailed:)];
- [m_request setDidFinishSelector:@selector(ASIHttpRequestSuceed:)];
- [m_request startAsynchronous];
- }
- - (void)ASIHttpRequestFailed:(ASIHTTPRequest *)m_request{
- [self hideDial];
- if (m_request) {
- [m_request release];
- }
- }
- - (void)ASIHttpRequestSuceed:(ASIHTTPRequest *)m_request{
- NSData *data = [m_request responseData];
- if (data)
- {
- NSString *string = [[NSString alloc] initWithData:dataencoding:NSUTF8StringEncoding];
- NSLog(@"%@",string);
- [contact clean];
- if (string)
- {
- [contact storeContacts:string Source:1];
- }
- [string release];
- }
- if (m_request) {
- [m_request release];
- }
}
小结:关于iPhone开发应用ASIHTTPRequest如何获取文件流的内容介绍完了,希望本文对你有所帮助!