
Untitled
By: a guest on
Apr 26th, 2012 | syntax:
None | size: 1.29 KB | hits: 20 | expires: Never
How to authenticate using sendSynchronous request in NSURLConnection
NSURLCredential *credential = [NSURLCredential credentialWithUser:@"user.me"
password:@"Passme@4me"
persistence:NSURLCredentialPersistenceForSession];
NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc]
initWithHost:@"proxy.net"
port:0
protocol:@"http"
realm:nil
authenticationMethod:NSURLAuthenticationMethodDefault];
[[NSURLCredentialStorage sharedCredentialStorage] setCredential:credential
forProtectionSpace:protectionSpace];
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://main.mainsite.com/" cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:30.0];
NSData* returnData=[[NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&err];
[NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&err];