首页 > Web开发 > 详细

[第三方]AFNetWorking3.0网络框架使用方法

时间:2015-12-17 15:37:12      阅读:309      评论:0      收藏:0      [点我收藏+]

官网地址https://github.com/AFNetworking/AFNetworking

#import <AFNetworking.h>

- (void)viewDidLoad {

    //GET方法
    //创建查询字符串
    NSString* str=@"http://apis.juhe.cn/cook/query";
    //创建查询条件的字典
    NSDictionary* dic=@{@"key":@"912b2db2ecd52723f74c1b7fec8eca38",@"menu":@"红烧肉",@"rn":@"20",@"pn":@"1"};
    //创建配置文件
    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
    //用配置文件初始化AFURLSessionManager
    AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
    //创建GET请求
    NSURLRequest *request = [[AFHTTPRequestSerializer serializer] requestWithMethod:@"GET" URLString:str parameters:dic error:nil];
    //创建数据任务
    NSURLSessionDataTask *dataTask = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
        if (error) {
            NSLog(@"Error: %@", error);
        } else {
            NSLog(@"%@",responseObject);
            NSDictionary* resultDic=[responseObject valueForKey:@"result"];
            array=[resultDic valueForKey:@"data"];
            NSLog(@"%@",array[0]);
            [table reloadData];
        }
    }];
    //开始数据任务
    [dataTask resume];

}

 

[第三方]AFNetWorking3.0网络框架使用方法

原文:http://www.cnblogs.com/death3721/p/5054106.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!