2011-03-07 8 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

+0

동기식 방법을 사용하여 프록시와 기본 웹 사이트 모두에 대해 인증을 수행 할 수있는 방법이 있습니까? – prajul

관련 문제