RestKit 0.20.0pre5:每个请求的HTTP标头 [英] RestKit 0.20.0pre5: HTTP headers per request

查看:119
本文介绍了RestKit 0.20.0pre5:每个请求的HTTP标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想发送一个带有GET请求的 If-Modified-Since http标头,由发出[RKObjectManager getObjectsAtPath:...]

i want to send an If-Modified-Since http header with a GET request, issued by [RKObjectManager getObjectsAtPath:...].

迁移指南告诉我只能为 RKObjectManager 实例设置全局默认请求标头:

the migration guide tells that i can set only "global" default request headers for an RKObjectManager instance:

RKObjectManager* objectManager = [RKObjectManager managerWithBaseURLString:url];
[objectManager.HTTPClient setDefaultHeader:@"If-Modified-Since" value:@"Sat, 29 Dec 2012 19:43:31 GMT"];

因为我想保留一个集中的 RKObjetManager 实例(通过 [RKObjectManager sharedManaged] ),这不是一个很好的选择。

since i want to keep a centralized RKObjetManager instance (via [RKObjectManager sharedManaged]), this is not really a good option.

正在创建一个特定的<每个请求之前code> RKObjectManager 并将我的http标头设置为默认唯一的解决方案还是有更好的方法?

is creating a specific RKObjectManager before each request and set my http headers as "default" the only solution or is there a better way?

推荐答案

这里有几个选项:


  1. 获取 NSURLRequest 对象使用 requestWithObject:method:path:parameters:,适当地配置 NSURLRequest ,然后调用 objectRequestOperationWithRequest:success:failure: managedObjectRequestOperationWithRequest:managedObjectContext:success:failure:。这将允许您一次性配置请求。

  2. 通过 RKHTTPRequestOperation 的自定义子类> setHTTPOperationClass: on RKObjectManager 。这将允许您挂钩子类,可以在对象管理器发出请求时配置每个NSURLRequest,让您集中配置。

  3. 在最新的开发分支上,您还可以注册<的​​子类code> RKObjectRequestOperation 使用将用于您选择的请求的管理器,使您能够在对象请求操作级别集中自定义。

  1. Obtain an NSURLRequest object using requestWithObject:method:path:parameters:, configure the NSURLRequest appropriately, and then invoke objectRequestOperationWithRequest:success:failure: or managedObjectRequestOperationWithRequest:managedObjectContext:success:failure:. This will let you configure the requests on a one-off basis.
  2. Configure a custom subclass of RKHTTPRequestOperation via setHTTPOperationClass: on RKObjectManager. This will let you hook subclass in that can configure every NSURLRequest as the object manager makes requests, letting you centralize the configuration.
  3. On the latest development branch, you can also register a subclass of RKObjectRequestOperation with the manager that will be used for requests of your choosing, enabling you to centralize customization at the object request operation level.

选项1或2可能最适合您概述的HTTP级别问题,但我提到作为在对象映射级别执行相同类型自定义的替代方法。

Options 1 or 2 are probably most appropriate for the HTTP level concern you outline, but I mention as an alternative for doing the same sort of customization at the object mapping level.

这篇关于RestKit 0.20.0pre5:每个请求的HTTP标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆