RestKit 0.20.0pre5:每个请求的HTTP标头 [英] RestKit 0.20.0pre5: HTTP headers per request
问题描述
我想发送一个带有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?
推荐答案
这里有几个选项:
- 获取
NSURLRequest
对象使用requestWithObject:method:path:parameters:
,适当地配置NSURLRequest
,然后调用objectRequestOperationWithRequest:success:failure:
或managedObjectRequestOperationWithRequest:managedObjectContext:success:failure:
。这将允许您一次性配置请求。 - 通过
RKHTTPRequestOperation
的自定义子类> setHTTPOperationClass: onRKObjectManager
。这将允许您挂钩子类,可以在对象管理器发出请求时配置每个NSURLRequest,让您集中配置。 - 在最新的开发分支上,您还可以注册<的子类code> RKObjectRequestOperation 使用将用于您选择的请求的管理器,使您能够在对象请求操作级别集中自定义。
- Obtain an
NSURLRequest
object usingrequestWithObject:method:path:parameters:
, configure theNSURLRequest
appropriately, and then invokeobjectRequestOperationWithRequest:success:failure:
ormanagedObjectRequestOperationWithRequest:managedObjectContext:success:failure:
. This will let you configure the requests on a one-off basis. - Configure a custom subclass of
RKHTTPRequestOperation
viasetHTTPOperationClass:
onRKObjectManager
. This will let you hook subclass in that can configure every NSURLRequest as the object manager makes requests, letting you centralize the configuration. - 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屋!