2

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];
Community
  • 1
  • 1
prajul
  • 1,216
  • 2
  • 15
  • 27

1 Answers1

0

what about trying with 2 distinct protection spaces... one for "proxy.net" and the other for "mainsite.com"... ?

roberto.buratti
  • 2,487
  • 1
  • 16
  • 10