我已經使用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