get

1。發一個get請求,

 

 

AFHTTPClient *bClient = [AFHTTPClient clientWithBaseURL

 [NSURLURLWithString:@"http://xxxx.com"]];

    

[bClientgetPath:nilparameters:nilsuccess:^(AFHTTPRequestOperation *operation,id responseObject)

     {

         NSLog(@"response description:%@",[responseObjectdescription]);

     }

   failure:^(AFHTTPRequestOperation *operation,NSError *error)

     {

         NSLog(@"error description:%@",[error description]);

     }];




2。發一個post請求



NSDictionary *dic = [[NSDictionaryalloc]initWithObjectsAndKeys:@"123",@"num",@"jack",@"name",nil];



   AFHTTPClient *aClient = [AFHTTPClientclientWithBaseURL:[NSURLURLWithString:@"http://www.xxxx.com"]];


//設置接受的數據類型爲json

 

[aClientsetDefaultHeader:@"Accept"value:@"application/json"];

//設置提交的數據編碼類型爲json格式

    [aClient setParameterEncoding:AFJSONParameterEncoding];

   [aClientpostPath:nilparameters:dicsuccess:^(AFHTTPRequestOperation*operation,id responseObject)

     {

     NSLog(@"response description:%@",[responseObject description]);

     }

       failure:^(AFHTTPRequestOperation *operation,NSError *error)

     {

      NSLog(@"error description:%@",[errordescription]);

     }];



http://www.cocoachina.com/applenews/devnews/2013/1106/7304.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章