Note that there are some explanatory texts on larger screens.

plurals
  1. PONSURLConnection - Disable the authentication challenge response mechanism
    primarykey
    data
    text
    <p><strong>SITUATION</strong></p> <ul> <li>Using AFNetworking (NSURLConnection) to access my server API</li> <li>The API needs Basic Authentication with token as username</li> <li>The API returns HTTP 401 when token is invalid</li> <li>I set the Basic Authentication headers before any request</li> <li><p>If it returns 401, I retry like this:</p> <pre><code>AFHTTPRequestOperation *requestOperation = [MyHTTPClient.sharedClient HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) { processSuccessBlock(operation, responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { processFailureBlock(operation, error); if (operation.response.statusCode == 401) [MyHTTPClient.sharedClient refreshTokenAndRetryOperation:operation success:processSuccessBlock failure:processFailureBlock]; }]; </code></pre></li> </ul> <p><strong>PROBLEM</strong></p> <ul> <li>When the server returns HTTP 401 with a Basic Authentication challenge, AFNetworking/NSURLConnection <strong>sends the identical request twice</strong> (initial request and then in answer to the authentication challenge)</li> <li>But because of the code above that I handle the HTTP 401 myself, <strong>this is totally unnecessary</strong> and I want it to stop answering the authentication challenge automatically</li> </ul> <p><strong>WHAT I'VE TRIED</strong></p> <ul> <li>Responding with <code>cancelAuthenticationChallenge:</code> to <code>willSendRequestForAuthenticationChallenge:</code> is aborting the second call, but it gives the error code -1012 (NSURLErrorUserCancelledAuthentication) instead of 401 and masks the real response</li> </ul> <p><strong>How do you disable the authentication challenge response mechanism so you get the servers response without calling it twice?</strong></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.
 

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