Using request specific HTTP headers with RestKit

2019-09-06 16:40发布

问题:

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;
}];


标签: ios restkit