AFNnetworking 快速教程,官方入门教程译
来源:互联网 发布:传奇网页版源码 编辑:程序博客网 时间:2024/06/05 04:27
AFNetworking官网入门教程简单翻译,学习
AFNetworking 是一个能够快速使用的ios和mac os x下的网络框架,它是构建在Foundation URL Loading System之上的,封装了网络的抽象层,可以方便的使用,AFNetworking是一个模块化架构,拥有丰富api的框架。
一、HTTP请求与操作:
1、AFHTTPRequestOperationMa
该类封装与Web应用程序进行通信通过HTTP,包括要求制作,响应序列化,网络可达性监控和安全性,以及要求经营管理的常见模式。
GET 请求:
[objc] view plaincopyprint?在CODE上查看代码片派生到我的代码片
AFHTTPRequestOperationMa
[manager GET:@"http://example.com/resources.json" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
POST 带有表单参数的POST请求:
[objc] view plaincopyprint?在CODE上查看代码片派生到我的代码片
AFHTTPRequestOperationMa
NSDictionary *parameters = @{@"foo": @"bar"};
[manager POST:@"http://example.com/resources.json" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
POST Multi-Part格式的表单文件上传请求:
[objc] view plaincopyprint?在CODE上查看代码片派生到我的代码片
AFHTTPRequestOperationMa
NSDictionary *parameters = @{@"foo": @"bar"};
NSURL *filePath = [NSURL fileURLWithPath:@"file://path/to/image.png"];
[manager POST:@"http://example.com/resources.json" parameters:parameters constructingBodyWithBloc
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
二、Session管理:
1、AFURLSessionManager:创建和管理制定的NSURLSession对象
2、NSURLSessionConfiguratio
创建一个下载任务:
[objc] view plaincopyprint?在CODE上查看代码片派生到我的代码片
NSURLSessionConfiguratio
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfigura
NSURL *URL = [NSURL URLWithString:@"http://example.com/upload"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
NSURL *filePath = [NSURL fileURLWithPath:@"file://path/to/image.png"];
NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithRequest:request fromFile:filePath progress:nil completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
}];
[uploadTask resume];
创建一个数据流任务:
[objc] view plaincopyprint?在CODE上查看代码片派生到我的代码片
NSURLSessionConfiguratio
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfigura
NSURL *URL = [NSURL URLWithString:@"http://example.com/upload"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
NSURLSessionDataTask *dataTask = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
}];
[dataTask resume];
四、使用AFHTTPRequestOperation
1、AFHTTPRequestOperation是使用HTTP或HTTPS协议的AFURLConnectionOperation
它封装的获取后的HTTP状态和类型将决定请求的成功与否。
2、虽然AFHTTPRequestOperationMa
通过GET方式:
[objc] view plaincopyprint?在CODE上查看代码片派生到我的代码片
NSURL *URL = [NSURL URLWithString:@"http://example.com/resources/123.json"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:request];
op.responseSerializer = [AFJSONResponseSerializer
[op setCompletionBlockWithSu
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
[[NSOperationQueue mainQueue] addOperation:op];
连续操作多个:
[objc] view plaincopyprint?在CODE上查看代码片派生到我的代码片
NSMutableArray *mutableOperations = [NSMutableArray array];
for (NSURL *fileURL in filesToUpload) {
}
NSArray *operations = [AFURLConnectionOperation
} completionBlock:^(NSArray *operations) {
}];
[[NSOperationQueue mainQueue] addOperations:operations waitUntilFinished:NO];
- AFNnetworking快速教程,官方入门教程译
- AFNnetworking快速教程,官方入门教程译
- AFNnetworking快速教程,官方入门教程译
- AFNnetworking快速教程,官方入门教程译
- AFNnetworking快速教程,官方入门教程译
- AFNnetworking快速教程,官方入门教程译
- AFNnetworking快速教程,官方入门教程译
- AFNnetworking快速教程,官方入门教程译
- AFNnetworking快速教程,官方入门教程译
- AFNnetworking快速教程,官方入门教程译
- AFNnetworking 快速教程,官方入门教程译
- AFNnetworking快速教程,官方入门教程译
- AFNnetworking快速教程,官方入门教程译
- AFNnetworking快速教程,官方入门教程译
- AFNnetworking快速教程,官方入门教程译
- 网络连接框架AFNnetworking快速教程,官方入门教程译
- maven 官方快速教程
- mysql教程,mysql快速入门教程
- OpenCV学习笔记(6):滤波filter2D()
- Struts2文件上传
- spring中JoinPoint参数介绍
- HPUX中vg00根盘镜像配置方法
- Myeclipse中遇到的一些配置问题
- AFNnetworking 快速教程,官方入门教程译
- 《Netty 权威指南》—— 选择Netty的理由
- 【数据结构-链表】单链表
- sublime配置全攻略
- c# winform窗体 调用js脚本语言,然后输出结果
- For JingJing
- opencv2.2+vs2008平台搭建完整过程及问题
- R文件报错原因及解决办法汇总
- Windows 2008 Server R2 FTP服务器的配置与防火墙设置