Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Setup NSURLConnection
  2. NSURL *URL = [NSURL URLWithString:url];
  3. NSURLRequest *request = [NSURLRequest requestWithURL:URL
  4.                                          cachePolicy:NSURLRequestUseProtocolCachePolicy
  5.                                      timeoutInterval:30.0];
  6.  
  7. NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
  8. [connection start];
  9. [connection release];
  10.  
  11. // NSURLConnection Delegates
  12. - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
  13.     if ([challenge previousFailureCount] == 0) {
  14.         NSLog(@"received authentication challenge");
  15.         NSURLCredential *newCredential = [NSURLCredential credentialWithUser:@"USER"
  16.                                                                     password:@"PASSWORD"
  17.                                                                  persistence:NSURLCredentialPersistenceForSession];
  18.         NSLog(@"credential created");
  19.         [[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge];
  20.         NSLog(@"responded to authentication challenge");    
  21.     }
  22.     else {
  23.         NSLog(@"previous authentication failure");
  24.     }
  25. }
  26.  
  27. - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
  28.     ...
  29. }
  30.  
  31. - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
  32.     ...
  33. }
  34.  
  35. - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
  36.     ...
  37. }
  38.  
  39. - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
  40.     ...
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement