问题
i want to send an If-Modified-Since http header with a GET request, issued by [RKObjectManager getObjectsAtPath:...].
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"];
since i want to keep a centralized RKObjetManager instance (via [RKObjectManager sharedManaged]), this is not really a good option.
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:
There are a few options here:
- Obtain an
NSURLRequestobject usingrequestWithObject:method:path:parameters:, configure theNSURLRequestappropriately, 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
RKHTTPRequestOperationviasetHTTPOperationClass: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
RKObjectRequestOperationwith the manager that will be used for requests of your choosing, enabling you to centralize customization at the object request operation level.
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.
来源:https://stackoverflow.com/questions/14192462/restkit-0-20-0pre5-http-headers-per-request