问题
I have to communicate with a REST API with a custom authorization scheme. It uses a authorization header witch I need to set based on the content of the request, so the server can check that I known the scheme.
I would like to use RestKit and its powerful Core Data utilization but I found it difficult to find a neat way to set this header for every different request. There isn't a thing like a delegate on RKObjectManager that is called before every request.
Maybe I missed something, could someone tell me if there is an easy way to do this? Thanks in advance.
回答1:
You can do something like
[RKObjectManager sharedManager] postObject:yourObjectToPost usingBlock:^(RKObjectLoader *loader) {
NSDictionary* httpHeaders =@{@"key1":@"value1",
@"key2":@"value2",
@"key3":@"value3"};
loader.additionalHTTPHeaders = httpHeaders;
loader.delegate = self;
}];
来源:https://stackoverflow.com/questions/11646775/using-request-specific-http-headers-with-restkit