iPhone開發(fā)應(yīng)用ASIHTTPRequest如何獲取文件流
作者:佚名
iPhone開發(fā)應(yīng)用ASIHTTPRequest如何獲取文件流是本文要介紹的內(nèi)容,主要講解的是如何獲取文件流,來看本文詳細(xì)代碼實現(xiàn)。
iPhone開發(fā)應(yīng)用ASIHTTPRequest如何獲取文件流是本文要介紹的內(nèi)容,主要講解的是如何獲取文件流,內(nèi)容不多,主要是基于代碼來實現(xiàn)文件流的獲取,不多說,來看詳細(xì)代碼。在服務(wù)器上獲取文件中的內(nèi)容,此例中的文件為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];
- }
}
小結(jié):關(guān)于iPhone開發(fā)應(yīng)用ASIHTTPRequest如何獲取文件流的內(nèi)容介紹完了,希望本文對你有所幫助!
責(zé)任編輯:zhaolei
來源:
互聯(lián)網(wǎng)