Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A synchronous <code>NSURLConnection</code> will absolutely work with <code>NSURLCredentialStorage</code>. Here's how things usually work:</p> <ol> <li><code>NSURLConnection</code> requests the page from the server</li> <li>The server replies with a 401 response</li> <li><code>NSURLConnection</code> looks to see what credentials it can glean from the URL</li> <li>If the URL did <strong>not</strong> provide full credentials (username and password), <code>NSURLConnection</code> will also consult <code>NSURLCredentialStorage</code> to fill in the gaps</li> <li>If full credentials have <em>still</em> not been determined, <code>NSURLConnection</code> will send the <code>-connection:didReceiveAuthenticationChallenge:</code> delegate method asking for credentials</li> <li>If the <code>NSURLConnection</code> now finally has full credentials, it retries the original request including authorization data.</li> </ol> <p>By using the synchronous connection method, you <strong>only</strong> lose out on step 5, the ability to provide custom authentication. So, you can either pre-provide authentication credentials in the URL, or place them in <code>NSURLCredentialStorage</code> before sending the request. e.g.</p> <pre><code>NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://user:pass@example.com"]]; [NSURLConnection sendSynchronousRequest:request returningResponse:NULL error:NULL]; </code></pre> <p>or:</p> <pre><code>NSURLCredential *credential = [NSURLCredential credentialWithUser:@"user" password:@"pass" persistence:NSURLCredentialPersistenceForSession]; NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc] initWithHost:@"example.com" port:0 protocol:@"http" realm:nil authenticationMethod:nil]; [[NSURLCredentialStorage sharedCredentialStorage] setDefaultCredential:credential forProtectionSpace:protectionSpace]; [protectionSpace release]; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://example.com"]]; [NSURLConnection sendSynchronousRequest:request returningResponse:NULL error:NULL]; </code></pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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