Can any one tell me how to send a authentication request using the NSURLConnection.I tried out the following code snippet by following the link stackoverflow question but still its not working.
I want to authenticate using synchronous request and authentication is asked twice
1.Over a proxy: proxy.net
2.Main site :main.mainsite.com (same code not listed here)
I have used the following code to do the same-
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];
But the proxy is blocking the request even though the credentials are correct.Can anyone give me a way to authenticate using the method
[NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&err];