NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)
Bardzo, bardzo frustrujące! Od tego czasu ciągnę za włosy moje. Używam samopodpisanego certyfikatu na moim serwerze Linode. Port ma 8000, nie można go uruchomić na 443. Nie sądzę jednak, że to jest powód. Oto mój kod, to jest 99% boilerplate:Żądania iOS HTTPS 101
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.myserver.com:8000/test.json"]];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
Na dole:
#pragma mark NSURLConnectionDelegate
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
NSLog(@"protectionSpace: %@", [protectionSpace authenticationMethod]);
// We only know how to handle NTLM authentication.
if([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodNTLM])
return YES;
// Explicitly reject ServerTrust. This is occasionally sent by IIS.
if([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodServerTrust])
return NO;
return NO;
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
[[challenge sender] continueWithoutCredentialForAuthenticationChallenge:challenge];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
NSLog(@"%@", response);
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
NSLog(@"%@", data);
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"didFailWithError");
NSLog([NSString stringWithFormat:@"Connection failed: %@", [error description]]);
}
OMG POMOC!
UPDATE
on pracował z tej metody delegata. Otrzymuję odpowiedź, ale jest problem.
- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
[[challenge sender] useCredential:[NSURLCredential
credentialWithUser:@"user"
password:@"password"
persistence:NSURLCredentialPersistencePermanent] forAuthenticationChallenge:challenge];
}
Podane przeze mnie "użytkownik" i "hasło są całkowicie losowe i nie są sprawdzane przez serwer. Jak mogę sprawdzić dane uwierzytelniające przed zaakceptowaniem połączenia na moim serwerze?
EDIT: Używam serwera node.js
„«użytkownik»i«hasło», które mam pod warunkiem są całkowicie przypadkowe i nie są sprawdzane przez serwer” - to już zupełnie inna kwestia. Powinieneś zadać to jako osobne pytanie i być może powrócić do tego pytania. Konfiguracja Linode może być nietypowa, więc możesz przejść do Super User lub Server Fault. (I prawdopodobnie powinieneś zaakceptować odpowiedź Fonix, ponieważ wydaje się, że pomogła ci rozwiązać problem). – jww