我已经使用NSMutableURLRequest很长时间来连接到我的服务器。为什么切换到HTTPS时,我通过NSURLRequest获得了authenticationchallenge?
为了避免双重roadtrips,我设置的USR /密码马上在头,像这样:
NSMutableURLRequest *request = [NSMutableURLRequest
requestWithURL:[NSURL URLWithString:url]
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:HTTP_REQUEST_TIMEOUT];
NSString *authStr = [NSString stringWithFormat:@"%@:%@", inUsr, inPwd];
NSString *authValue = [NSString stringWithFormat:@"Basic %@", [[authStr dataUsingEncoding:NSISOLatin1StringEncoding] base64EncodedStringWithOptions:0]];
[request setValue:authValue forHTTPHeaderField:@"Authorization"];
这一直很好,在“willSendRequestForAuthenticationChallenge”是从来没有所谓的,除非有一些错误,这样的方法一直看起来像:
- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
NSDictionary *errorInfo = ((NSHTTPURLResponse *) challenge.failureResponse).allHeaderFields;
NSError *error; = [NSError errorWithDomain:@"httprequesthandler" code:WRONG_CREDENTIALS userInfo:errorInfo];
[delegate finishedWithErrors:error];
但是现在,我使用的是相同的URL的一如既往,只有“https”开头的不是“http”,突然这个方法被调用每次。
我希望我的请求按照常规工作,即填充基本头文件和只有一个请求到服务器。
我不确定我错过了什么,所以指针将非常感谢!
好的。谢谢! – Mathias