我遇到了一个小问题。我正在连接到使用基本身份验证的 Web 服务,现在我希望用户能够:能够注销,或者每次发出请求时都进行新的身份验证。现在身份验证似乎被缓存了。我该怎么做?
我试图在末尾附加 #
,但这似乎没有用。 URL 具有以下格式:
www.example.org/mywebservice/data
NSURL* url = [NSURL URLWithString: @"www.example.org/mywebservice/data"];
NSURLRequest* request = [[NSURLRequest alloc] initWithURL:url];
NSURLConnection* newConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
self.myConnection = newConnection;
[request release];
[newConnection release];
最佳答案
我想你想清除以前请求的缓存,并且每次都想在登录时做新的请求。因此,在进行登录请求之前,只需将代码放在下面
NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies])
{
[storage deleteCookie:cookie];
}
[[NSURLCache sharedURLCache] removeAllCachedResponses];
可能对你有帮助
快乐编码:)
关于iphone - iPhone 上的基本身份验证注销,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11099442/