谁能告诉我如何使用 NSURLConnection 发送身份验证请求。我按照链接stackoverflow 问题尝试了以下代码片段,但仍然无法正常工作。
我想使用同步请求进行身份验证,并且两次询问身份验证
1.通过代理:proxy.net
2.主站点:main.mainsite.com(此处未列出相同的代码)
我已经使用以下代码来做同样的事情 -
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];