Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 26th, 2012  |  syntax: None  |  size: 1.29 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to authenticate using sendSynchronous request in NSURLConnection
  2. NSURLCredential *credential = [NSURLCredential credentialWithUser:@"user.me"
  3.                                                          password:@"Passme@4me"
  4.                                                       persistence:NSURLCredentialPersistenceForSession];
  5.  
  6.  
  7. NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc]
  8.                                          initWithHost:@"proxy.net"
  9.                                          port:0
  10.                                          protocol:@"http"
  11.                                          realm:nil
  12.                                          authenticationMethod:NSURLAuthenticationMethodDefault];
  13.  
  14.  
  15. [[NSURLCredentialStorage sharedCredentialStorage] setCredential:credential
  16.                                                     forProtectionSpace:protectionSpace];
  17.  
  18. NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://main.mainsite.com/"  cachePolicy:NSURLRequestUseProtocolCachePolicy
  19.                                       timeoutInterval:30.0];
  20.  
  21. NSData* returnData=[[NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&err];
  22.        
  23. [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&err];