proxy authorization on iPhone simulator
Have such a problem, hope you'll help me.. Can't find anywhere. Here is the code i'm using:
NSURL *serverURL = [NSURL URLWithString:@"http://someServer.com/Lo开发者_运维知识库gin"];
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];
When I want to acces to the server http://someServer.com/Login from browser on computer all ok.
When I tryied to acces the same server from safary on iPhone simulator - authorization window appears after authorization all was OK.
But when I perform this request in a program way on iPhone simulator, code sample I have posted. Next error appears:
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.
How can I solve this problem?? Thanx!
seems that you need to send the authentication credentials when you make the call.
Try to use NSURLConnection
class to make the call, set the delegate and implement the following method
-(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
}
}
精彩评论