ios - AFHTTPRequestOperation 与 AFHTTPRequestOperationManager

标签 ios objective-c afnetworking-2

我是 objective-c 的完全菜鸟,所以请原谅这个愚蠢的问题。

我已经能够按照 AFNetworking 2.0 的指南使用 AFHTTPRequestOperationManager 发送帖子和获取请求。

我开始研究响应缓存,据我所知,AFHTTPRequestOperation 具有 setCachePolicy。我开始将所有调用切换到 AFHTTPRequestOperation,但我发现它很难使用。

我是否为自己创造了不必要的工作?如果服务器的缓存 header 设置正确,我是否需要在客户端使用 AFNetworking 执行任何操作?

使用 AFHTTPRequestOperationManager:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

[manager POST:urlString parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {

使用 AFHTTPRequestOperation:

AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:request];
op.responseSerializer = [AFJSONResponseSerializer serializer];
[op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

我真的希望这是有道理的...

最佳答案

AFHTTPRequestOperation 是 AFURLConnectionOperation 的子类,用于使用 HTTP 或 HTTPS 协议(protocol)的请求。它封装了可接受的状态代码和内容类型的概念,它们决定了请求的成功或失败。

AFHTTPRequestOperationManager 封装了通过 HTTP 与 Web 应用程序通信的常见模式,包括请求创建、响应序列化、网络可达性监控和安全性,以及请求操作管理。

关于ios - AFHTTPRequestOperation 与 AFHTTPRequestOperationManager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21338173/

相关文章:

ios - 使用 AFNetworking 2.0 加载图像

php - 无法使用 AFNetworking 2 和 Slim PHP 框架上传图像

ios - AFNetworking 回调 - 委托(delegate)还是通知?

ios - 无法让微调器出现

objective-c - MPMoviePlayerController 覆盖 iOS 6

ios - XCode 7 和 iOS 8 自动布局顶部约束问题

ios - 在 UITextField 上点击时将 UIButton 移动到键盘上方

ios - 如何在后台更新 RSS 提要

Javascript 仅在 ios 上抛出类型错误

ios - 识别 subview 的类