2011-03-07 86 views
0

有这样的问题,希望你能帮助我..找不到任何地方。下面是我使用的代码:iPhone模拟器上的代理授权

NSURL *serverURL = [NSURL URLWithString:@"http://someServer.com/Login"]; 
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:serverURL]; 
[request addValue:@"text/plain" forHTTPHeaderField:@"ACCEPT"]; 
[request setHTTPMethod:@"POST"]; 

[request setCachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData]; 

NSData *data = [encodedString dataUsingEncoding:NSUTF8StringEncoding]; 
[request setHTTPBody:data]; 

URLLoader *loader = [URLLoader loaderWithRequest:request]; 

当我想从电脑都可以在浏览器中查看在服务器http://someServer.com/Login

当我尝试从iPhone模拟器上的safary访问相同的服务器 - 授权后出现授权窗口一切正常。

但是,当我在iPhone模拟器上以程序方式执行此请求时,我发布了代码示例。出现下一个错误:

The following error was encountered: 
Cache Access Denied. 

Sorry, you are not currently allowed to request: 
    http://someserver.com/Login 
from this cache until you have authenticated yourself. 

我该如何解决这个问题?感谢名单!

回答

1

似乎您在拨打电话时需要发送身份验证凭据。 尝试使用NSURLConnection类拨打电话,设置委托,并实现以下方法

-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{ 
    if ([challenge previousFailureCount] == 0) { 
     NSURLCredential *newCredential; 
     newCredential=[NSURLCredential credentialWithUser:@"ABC" 
               password:@"XYZ" 
               persistence:NSURLCredentialPersistenceNone]; 
     [[challenge sender] useCredential:newCredential 
       forAuthenticationChallenge:challenge]; 

    } else { 

     [[challenge sender] cancelAuthenticationChallenge:challenge]; 
     // inform the user that the user name and password 
     // in the preferences are incorrect 
    } 

} 
+0

感谢名单,我只是说这个服务器列表中使用它没有代理。 – yozhik 2011-03-07 14:57:50

+0

有什么办法可以使用同步方法对代理和主网站进行身份验证? – prajul 2012-02-25 20:09:03