get

来源:互联网 发布:办公软件表格下载 编辑:程序博客网 时间:2024/05/29 04:48

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

0 0
原创粉丝点击