AFNetWorking网络库教程

AFNetWorking 图片本地缓存的问题

http://www.cnblogs.com/Wendale-Zhang/archive/2013/01/17/2864442.html

 

今天看了下AFNetwoking这个通讯库,简单研究了一下

 

(1)POST请求

//建立URL

   NSURL* url = [NSURL URLWithString:@"XXXX"];

//表单数据

 

    NSDictionary* requestDict = [NSDictionarydictionaryWithObjectsAndKeys:themeId,@"themeId", nil];

 

 

    //建立POST请求

   AFHTTPClient *aClient = [AFHTTPClient  clientWithBaseURL:url];

   //设置接受的数据类型为json

    [aClient setDefaultHeader:@"Accept"value:@"application/json"];

   //设置提交的数据编码类型为json格式

   [aClient setParameterEncoding:AFFormURLParameterEncoding];

  //开始请求

    [aClient postPath:nil   parameters:requestDictsuccess:^(AFHTTPRequestOperation*operation,id responseObject)

   {

       //解析数据

        NSDictionary* Jsondict = [self parserJson:responseObject];

       NSLog(@"%@",Jsondict);

   }

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

    {

   }];

 

 

(2)GET请求

 

//建立URL

   NSURL* url = [NSURL URLWithString:@"XXXX"];

//建立请求

 

AFHTTPClient *bClient = [AFHTTPClient clientWithBaseURL:url];

        //开始请求

[bClientgetPath:nil   parameters:nil  success:^(AFHTTPRequestOperation *operation,id responseObject)

    {

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

     }

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

    {

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

     }];

原文地址:https://www.cnblogs.com/kevingod/p/3375254.html