title: Handling a 401 response with sendAsynchronousRequest:queue:completionHandler:
body: <p>I'm making an async url request with the new iOS 5 method: sendAsynchronousRequest:queue:completionHandler:. This uses a block to handle the response, but no NSURLConnectionDelegate delegate methods are being called? I can't see a way to set the delegate for the NSUrlConnection class in this instance?</p>
  
  <pre><code>[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
  
     NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
  
     NSLog(@"HTTP response code: %i", httpResponse.statusCode);
  
     if (error != nil) {
         NSLog(@"There was error with the synchronous request: %@", error.description);              
     }
  }];
  </code></pre>
  
  <p>The reason I need the delegate methods is because one of my calls gets a 401 response, which iOS handles in a different way - deferring authentication to delegate methods. When a 401 response comes back - httpResponse.statusCode is just "0". </p>
  
  <p>Is there a way to stop iOS from trying to handle a 401 differently? In particular, I'm thinking I need to use the continueWithoutCredentialForAuthenticationChallenge: delegate method - but no delegates are being called in this case.</p>
  
  <p>Thanks!</p>