NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)
Sehr, sehr frustrierend! Ich habe mir damit stundenlang die Haare gezogen. Ich verwende ein selbstsigniertes Zertifikat auf meinem Linode-Server. Der Port ist 8000, konnte nicht auf 443 arbeiten. Ich glaube nicht, dass dies der Grund ist. Hier ist mein Code, es ist 99% vorformulierten:iOS HTTPS-Anfragen 101
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.myserver.com:8000/test.json"]];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
Am Boden:
#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 HELP!
UPDATE
es mit diesem Delegatmethode gearbeitet. Ich erhalte die Antwort, aber es gibt ein Problem.
- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
[[challenge sender] useCredential:[NSURLCredential
credentialWithUser:@"user"
password:@"password"
persistence:NSURLCredentialPersistencePermanent] forAuthenticationChallenge:challenge];
}
Die "Benutzer" und "Passwort", die ich zur Verfügung gestellt habe, sind völlig zufällig und werden nicht vom Server überprüft. Wie kann ich die Anmeldedaten vor dem Akzeptieren der Verbindung auf meinem Server überprüfen?
EDIT: Ich bin ein Node.js Server
„Der‚Benutzer‘und‚Passwort‘, die ich zur Verfügung gestellt habe völlig zufällig sind und nicht vom Server überprüft“ - das ist eine andere Frage. Sie sollten es als separate Frage stellen und vielleicht auf diese Frage zurückkommen. Die Linode-Konfiguration ist möglicherweise nicht am Thema, sodass Sie möglicherweise zu Super User oder Server Fault wechseln müssen. (Und Sie sollten wahrscheinlich Fonix Antwort akzeptieren, da es Ihnen geholfen hat, das Problem zu lösen). – jww