I think I see what happened, but I don't know how to get around it. I
was apparently logged off the remote site at some point, and my
authentication response function didn't pick up and reauthorize me
properly. I was able to temporarily fix the situation by passing the
remote site URL into a TTWebController and authenticating that way.
Here are the function calls from my data model class:
- (void)load:(TTURLRequestCachePolicy)cachePolicy more:(BOOL)more {
if (!self.isLoading) {
NSString* url = @"http://<remotesite>/data.json";
TTURLRequest* request = [TTURLRequest requestWithURL:url
delegate:self];
id<TTURLResponse> response = [[TTURLDataResponse alloc] init];
request.cachePolicy = TTURLRequestCachePolicyNone;
request.response = response;
[request send];
}
}
- (void)request:(TTURLRequest *)request
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge
*)challenge {
NSLog(@"Received authentication challenge");
if ([challenge previousFailureCount] == 0) {
NSURLCredential *newCredential = [NSURLCredential
credentialWithUser:_username password:_password
persistence:NSURLCredentialPersistenceNone];
[[challenge sender] useCredential:newCredential
forAuthenticationChallenge:challenge];
}
else {
[[challenge sender] cancelAuthenticationChallenge:challenge];
}
}
The NSLog output from my didReceiveAuthenticationChallenge function
never got called while I was experiencing the 401 error. I thought
that it was supposed to be called when the site returns a 401 error.
In fact, I've personally witnessed the log entry from this function in
this application in the recent past.
Any suggestions on how I can properly pass authentication to the
remote site? I'm guessing that the user/password info need to be put
into the headers of the TTURLRequest?