Note that there are some explanatory texts on larger screens.

plurals
  1. PONSURLConnection using basic auth fails on Tiger, succeeds on Panther and Leopard
    primarykey
    data
    text
    <p>I have a program running on Panther, Tiger, and Leopard systems and using the following method for NSURLConnection authentication ("encodedUserPass" is the auth string with the word Basic followed by the base64-encoded user:pass)</p> <pre><code>[theRequest addValue:encodedUserPass forHTTPHeaderField:@"Authorization"]; NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; </code></pre> <p>...later...in didReceiveAuthenticationChallenge</p> <pre><code>if ([challenge previousFailureCount] == 0) { NSURLCredential *newCredential; newCredential=[NSURLCredential credentialWithUser:login_name password:password persistence:NSURLCredentialPersistenceNone]; [[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge]; } </code></pre> <p>This works perfectly fine on Panther and Leopard systems but fails utterly on Tiger. It is odd, though, that even on Panther and Leopard "didReceiveAuthenticationChallenge" is usually called (i.e., setting the headers manually seems not to work).</p> <p>On Tiger, didReceiveAuthenticationChallenge is always called, tries to respond as shown above, and is then called again with failure.</p> <p>Two questions: (i) Why doesn't setting the headers manually work? and (2) Why does the method shown above fail on Tiger (10.4)?</p> <p><strong><em>LATER UPDATE</em></strong>:</p> <p>After some thought, I realized that there had to be something wrong with my base64-encoding method, and there was: I didn't append equals signs to bring the base64 string up to a multiple of 4 characters. I solved it with</p> <pre><code>while ([bareString length] % 4) [bareString appendString:@"="]; </code></pre> <p>And now the program works on all three platforms. So question (i) is answered: setting the headers manually didn't work because I wasn't padding with equals signs.</p> <p>Question (ii) remains, though: why can't I use didReceiveAuthenticationChallenge successfuly in Tiger?</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