Note that there are some explanatory texts on larger screens.

plurals
  1. POBasicAuthentication and RestKit
    primarykey
    data
    text
    <p>I have a question about RestKit and BasicAuth.</p> <p>I tried a server API with Basic Auth with this sample code:</p> <pre><code>RKObjectManager *objectManager = [RKObjectManager sharedManager]; [objectManager.HTTPClient setAuthorizationHeaderWithUsername:@"test" password:@"test"]; [objectManager getObjectsAtPath:@"/server/testapi" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) { NSArray* statuses = [mappingResult array]; NSLog(@"Loaded statuses: %@", statuses); } failure:^(RKObjectRequestOperation *operation, NSError *error) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:[error localizedDescription] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; NSLog(@"Hit error: %@", error); }]; </code></pre> <p>But I obtain this error:</p> <pre><code>E restkit.network:RKObjectRequestOperation.m:576 Object request failed: Underlying HTTP request operation failed with error: Error Domain=org.restkit.RestKit.ErrorDomain Code=-1011 "Expected status code in (200), got 401" UserInfo=0xb44ad30 {NSLocalizedRecoverySuggestion={"detail": "Authentication credentials were not provided."}, AFNetworkingOperationFailingURLRequestErrorKey=&lt;NSMutableURLRequest: 0xda5c650&gt; { URL: http://myhost/match/calendar }, NSErrorFailingURLKey=http://myhost/match/calendar, NSLocalizedDescription=Expected status code in (200), got 401, AFNetworkingOperationFailingURLResponseErrorKey=&lt;NSHTTPURLResponse: 0xda2c4f0&gt; { URL: http://myhost/match/calendar/ } { status code: 401, headers { Allow = "GET, POST, HEAD, OPTIONS"; "Content-Type" = "application/json"; Date = "Sat, 21 Dec 2013 13:27:34 GMT"; Server = "WSGIServer/0.1 Python/2.7.3"; Vary = Accept; "Www-Authenticate" = "Basic realm=\"api\""; } }} </code></pre> <p>In my AFHTTPClient I see:</p> <pre><code>{ Accept = "application/json"; "Accept-Encoding" = "gzip, deflate"; "Accept-Language" = "it;q=1, en;q=0.9, fr;q=0.8, de;q=0.7, zh-Hans;q=0.6, zh-Hant;q=0.5"; Authorization = "Basic dGVzdDpmYW50YQ=="; "User-Agent" = "iFanta/1.0 (iPhone Simulator; iOS 7.0; Scale/2.00)"; } </code></pre> <p>but on my server I not see the corresponding to HTTP header. Why the default AFHTTPClient headers not corresponding to HTTP header request?</p> <p>If I test with my browser it works well;</p> <p>If I disable basic Auth on the server it works well;</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload