AFNetworkingV2Client改进版
2014-01-24 16:29
417 查看
AFNetworkingV2Client
====================
一、AFHTTPClient是什么?
AFHTTPClient 是在AFNetworkingV2基础上做的改进,主要实现AFHTTPClientV2类,该类根据当前OS进行选择HTTP请求处理方式,
IOS7及其以后,采用AFHTTPSessionManager,IOS7之前采用AFHTTPRequestOperationManager。
二、改进:
1)在AFNetworkingV2中AFHTTPResponseSerializer属性增加@"text/html"
self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];
2)在AFHTTPSessionManager和AFHTTPRequestOperationManager类中增加header方法如下:
- (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field;
三、使用方法:
工程示例采用糗事百科的嫩草API
/*
- (void)loadData
{
[self.indicatorView startAnimating];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:2];
[params setObject:@"5" forKey:@"count"];
[params setObject:@"1" forKey:@"page"];
__weak QiushiViewController *weakSelf = self;
[AFHTTPClientV2 requestWithBaseURLStr:@"http://m2.qiushibaike.com/article/list/latest" params:params httpMethod:HttpMethodGet successBlock:^(id responseObject) {
NSLog(@"GET responseObject: %@",responseObject);
QiushiViewController *strongSelf = weakSelf;
[strongSelf.indicatorView stopAnimating];
if ([responseObject isKindOfClass:[NSDictionary class]]) {
NSArray *array = [responseObject objectForKey:@"items"];
NSMutableArray *strollArray = [NSMutableArray arrayWithCapacity:[array count]];
for (int i = 0; i < [array count]; i++) {
NSDictionary *qiushiDic = [array objectAtIndex:i];
QiuShi *qs = [[QiuShi alloc] initWithQiuShiDictionary:qiushiDic];
[strollArray addObject:qs];
}
strongSelf.dataArray = strollArray;
}
} failedBlock:^(NSError *error) {
NSLog(@"GET error: %@",error);
QiushiViewController *strongSelf = weakSelf;
[strongSelf.indicatorView stopAnimating];
}];
}
*/
四、QA交流
本工程希望能给IOS开发者提供些帮助,同时更希望IOS同行,能提出宝贵意见,欢迎拍砖
项目gitHub地址:https://github.com/pjk1129/AFNetworkingV2Client
====================
一、AFHTTPClient是什么?
AFHTTPClient 是在AFNetworkingV2基础上做的改进,主要实现AFHTTPClientV2类,该类根据当前OS进行选择HTTP请求处理方式,
IOS7及其以后,采用AFHTTPSessionManager,IOS7之前采用AFHTTPRequestOperationManager。
二、改进:
1)在AFNetworkingV2中AFHTTPResponseSerializer属性增加@"text/html"
self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];
2)在AFHTTPSessionManager和AFHTTPRequestOperationManager类中增加header方法如下:
- (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field;
三、使用方法:
工程示例采用糗事百科的嫩草API
/*
- (void)loadData
{
[self.indicatorView startAnimating];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:2];
[params setObject:@"5" forKey:@"count"];
[params setObject:@"1" forKey:@"page"];
__weak QiushiViewController *weakSelf = self;
[AFHTTPClientV2 requestWithBaseURLStr:@"http://m2.qiushibaike.com/article/list/latest" params:params httpMethod:HttpMethodGet successBlock:^(id responseObject) {
NSLog(@"GET responseObject: %@",responseObject);
QiushiViewController *strongSelf = weakSelf;
[strongSelf.indicatorView stopAnimating];
if ([responseObject isKindOfClass:[NSDictionary class]]) {
NSArray *array = [responseObject objectForKey:@"items"];
NSMutableArray *strollArray = [NSMutableArray arrayWithCapacity:[array count]];
for (int i = 0; i < [array count]; i++) {
NSDictionary *qiushiDic = [array objectAtIndex:i];
QiuShi *qs = [[QiuShi alloc] initWithQiuShiDictionary:qiushiDic];
[strollArray addObject:qs];
}
strongSelf.dataArray = strollArray;
}
} failedBlock:^(NSError *error) {
NSLog(@"GET error: %@",error);
QiushiViewController *strongSelf = weakSelf;
[strongSelf.indicatorView stopAnimating];
}];
}
*/
四、QA交流
本工程希望能给IOS开发者提供些帮助,同时更希望IOS同行,能提出宝贵意见,欢迎拍砖
项目gitHub地址:https://github.com/pjk1129/AFNetworkingV2Client
相关文章推荐
- qt下qml和c++交互信号槽机制测试
- CentOS下通过locale来设置字符集
- bae3.0第四步 第一个polls系统
- 错误:[将截断字符串或二进制数据。\r\n语句已终止。]
- json全套
- synthesis-of-weak-property-only-allowed-in-arc-or-gc-mode ARC属性
- ubuntu 常见错误--Could not get lock /var/lib/dpkg/lock
- js截取字符串
- Windows 应用程序交互过程
- 联想集团收购IBM x86服务器业务
- cacti监控一览无余
- hdu 2152 有上下界的母函数使用
- Android增量升级的方法和原理详细介绍
- 常用的sql语句
- Gartner对未来几年移动应用的前瞻
- Microsoft Office Professional Plus 2007在安装过程中出错
- 有爱就有恨
- 前尘往事成云烟
- 未设置 WEB 服务器网卡的 DNS,导致外网无法访问
- 图的深度优先遍历,基于邻接链表的非递归实现