ASIHTTPRequest 简单使用
生活随笔
收集整理的這篇文章主要介紹了
ASIHTTPRequest 简单使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
ASIHTTPResquest 框架功能強大,應用非常多。
曾經寫過ASIHTTPResquest的導入,如今就看一下基本使用
記一下當中基礎的操作;
1、發送同步請求;
NSURL * url = [NSURL URLWithString:@"http://www.baidu.com"];//構造url字符串ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];//構造請求對象[request startSynchronous];//開始同步請求 <span style="font-family: Arial, Helvetica, sans-serif;">startSynchronous 指的是同步</span>NSString *response = [request responseString];//獲取請求字符串NSLog(@"%@",response);?
2、發送異步請求
NSURL * url = [NSURL URLWithString:@"http://www.baidu.com"];ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];[request startAsynchronous];[request setDelegate:self];//設置托付NSString *response = [request responseString];NSLog(@"%@",response);異步請求的delegate;
與同步請求不同異步請求須要攔截HTTP會話事件。并將事件托付給代理來處理。
托付:ASIHTTPRequestDelegate
-(void)requestStarted:(ASIHTTPRequest *)request {//請求開始的時候調用 } -(void)requestFinished:(ASIHTTPRequest *)request {//請求完畢的時候調用 } -(void) requestFailed:(ASIHTTPRequest *)request {//請求失敗的時候調用 } -(void)request:(ASIHTTPRequest *)request didReceiveResponseHeaders:(NSDictionary *)responseHeaders {//收到HTTP頭的時候調用 }還有非常多托付方法能夠點進去看一下。
ASIHTTPResquest還支持 塊
用塊就不須要實現托付了。
總結
以上是生活随笔為你收集整理的ASIHTTPRequest 简单使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MAP的get与containskey
- 下一篇: 燕子的拼音