How do I set basic authentication with RestKit 0.20.0?

前端 未结 1 1647
我在风中等你
我在风中等你 2020-12-09 06:18

I\'m trying to use RestKit to call an endpoint that requires basic authentication.

RKObjectMapping *mapping = [RKOb         


        
1条回答
  •  春和景丽
    2020-12-09 07:03

    Using the objectmanager this would be something like:

    NSURL* url = [[NSURL alloc]initWithString:@"http://rest.url.com"];
    RKObjectManager* objectManager = [RKObjectManager managerWithBaseURL:url];
    
    [objectManager.HTTPClient setAuthorizationHeaderWithUsername:@"username" password:@"password"];
    

    Then, after setting the correct request/response you can use the objectmanager to do a get/post/etc:

    [objectManager getObjectsAtPath:endpoint parameters:parameters success:
         ^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
             // do something
         }  
         failure:^(RKObjectRequestOperation *operation, NSError *error) {
             // do something
         }
    ];
    

    0 讨论(0)
提交回复
热议问题