views:

401

answers:

1

I felt like I'm having the same issues as addressed here. But everything I try doesn't seem to work.

The program goes as follows:

  • I'm asking for user credentials (username/password)
  • Then I do some calls to the server downloading information.
  • When its finished, I display a set of users, the user clicks on one, then is asked for the password for that account
  • I then make another request to the server and check to see if I get the right information back (therefore verifying the username/password just given is correct)

The problem is, the last call is similar (same url, different credentials) to one that I do in the initial download. Regardless of what the user puts in for the second credentials the "correct" information comes back. I think this is because it is caching the response, but I can't figure out how to stop it from doing that.

I'm have a class that makes the connection and returns the downloaded data. And I make a new class for every connection. So I'm not really sure why its saving data.

I have a NSMutableURLRequest in which I do the following:

 [theRequest setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];

(I have also tried, NSURLRequestReloadRevalidatingCacheData and NSURLRequestReloadIgnoringLocalAndRemoteCacheData)

I've also implemnted the functions:

- (NSCachedURLResponse *)connection:(NSURLConnection *)connection   
                  willCacheResponse:(NSCachedURLResponse *)cachedResponse {
return nil;
}

- (BOOL)connectionShouldUseCredentialStorage:(NSURLConnection *)connection {
return NO;
}

With the last one I don't fully understand it. So I tired YES and NO. And I've tried various NSURLRequest cache policies.

Any help on what my issue might be would be very helpful. Thank you.

+1  A: 

Just a guess, but would using

NSURLRequestReloadIgnoringLocalAndRemoteCacheData

rather than

NSURLRequestReloadIgnoringLocalCacheData

make any difference?

mjhoy
I didn't even know that existed, but no, it didn't work. Any more ideas?
RyanJM
What about NSHTTPCookieStorage? Try deleting the cookies for the URL, before the second request, or setting [[NSHTTPCookieStorage sharedStorage] setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyNever]
mjhoy
Thank you!! I used [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyNever]; and it did exactly what I needed to.
RyanJM