ASIHttpRequest載入網路資料和上傳資料功能,asihttprequest載入

來源:互聯網
上載者:User

ASIHttpRequest載入網路資料和上傳資料功能,asihttprequest載入

使用ASIHttpRequest第三庫,需要配置

二,

上傳資料功能使用ASIFromDataRequest(可以上傳二進位和字串給伺服器)

下面來牛刀小試

//建立一個工程,匯入第三方庫,在AppDelegate.h#import <UIKit/UIKit.h>#import "ASIFormDataRequest.h"@interface AppDelegate : UIResponder <UIApplicationDelegate,ASIHTTPRequestDelegate>{    //聲明資料請求的成員變數    ASIFormDataRequest *_request;}@property (strong, nonatomic) UIWindow *window;@end
//在AppDelegate.m裡寫的代碼//通過POST請求載入資料NSURL *url=[NSURL URLWithString:@"http://10.0.8.8/sns/my/login.php"];//執行個體化成對象_request=[[ASIFormDataRequest alloc]initWithURL:url];//佈建要求方式[_request setRequestMethod:@"post"];//添加參數[_request addPostValue:@"aa_Zx" forKey:@"username"];[_request addPostValue:@"ffff" forKey:@"password"];//設定代理回調_request.delegate=self;//請求資料[_request startAsynchronous];//非同步請求,多線程
#param -mark ASIHttpRequest-(void)requestFinished:(ASIHTTPRequest *)request{NSDictionary *dict=[NSJSONSerialization  JSONObjectWithData:request.responseData options:NSJSONReadingMutableContainers error:nil];   NSLog(@"%@",dict);}- (void)requestFailed:(ASIHTTPRequest *)request{    NSLog(@"請求失敗");}

 三,載入網路資料,ASIHttpRequest(所有格式的資料都能載入)

-(void)startLoadWebData:(NSString *)strURL{//執行個體化ASIHttpRequest對象NSURL *url=[NSURL URLWithString:strURL];_request=[[ASIHTTPRequest alloc]initWithURL:url];_requent.delegate=self;//開始載入資料[_requenst startAsynchronous];}#pragma -mark ASIHttpRequestDelegate//請求成功時調用該方法-(void)requestFinished:(ASIHTTPRequest *)request{NSDictionary *dict=[NSJSONSerialization JSONObjectWithData:request.responseDataoptions:NSJSONReadingMutableContainers error:nil];//代理接收資料[self.delegate reciveData:[dict objectForKey:@"application"];}//請求網路資料失敗時調用該方法-(void)requestFailed:(ASIHTTPRequest *)request{NSLog(@"failed");}

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.