Skip to content

Instantly share code, notes, and snippets.

@yoghi
Created December 13, 2012 16:10
Show Gist options
  • Save yoghi/4277504 to your computer and use it in GitHub Desktop.
Save yoghi/4277504 to your computer and use it in GitHub Desktop.
RestKit connect to rest service behind basic autentication
NSString *url = @"http://rest.local/test";
NSURL *baseURL = [NSURL URLWithString:url];
AFHTTPClient* client = [[AFHTTPClient alloc] initWithBaseURL:baseURL];
[client setAuthorizationHeaderWithUsername:@"demo" password:@"demo"];
[client setDefaultHeader:@"Accept" value:RKMIMETypeJSON];
RKObjectManager *objectManager = [[RKObjectManager alloc] initWithHTTPClient:client];
[RKObjectManager setSharedManager:objectManager];
NSURLRequest *request = [NSURLRequest requestWithURL:baseURL];
RKObjectRequestOperation *operation = [objectManager objectRequestOperationWithRequest:request success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSLog(@"ok");
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"not ok");
}];
[operation start];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment