IOS AFN (第三方请求)

 

什么是AFN
全称是AFNetworking,是对NSURLConnection、NSURLSession的一层封装
虽然运行效率没有ASI高,但是使用比ASI简单
在iOS开发中,使用比较广泛

AFN的github地址
https://github.com/AFNetworking/AFNetworking

 

技术分享

版本

适用iOS版本

Xcode要求

2.0+

iOS 6.0+

Xcode 5.0+

1.x

iOS 5.0

 

0.10.x

iOS 4.3

 

技术分享

AFHTTPRequestOperationManager
AFN中最重要的对象之一
封装了HTTP请求的常见处理
GET\POST请求
解析服务器的响应数据

创建
AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];

 

技术分享

 

GET请求 - (AFHTTPRequestOperation *)GET:(NSString *)URLString parameters:(id)parameters success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure POST请求 - (AFHTTPRequestOperation *)POST:(NSString *)URLString parameters:(id)parameters success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure

技术分享

技术分享

 

 技术分享

技术分享