Using request specific HTTP headers with RestKit

强颜欢笑 提交于 2019-12-12 01:37:20

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!