同様の問題がありました。私の場合、任意の証明書を受け入れることができる 2 つのデリゲート メソッドを使用して、必要に応じて ssl で動作する非同期接続がありました。
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
}
しかし、私は同期的に同じことをすることに固執していました。あなたの投稿と、残念ながら NSURLConnection で同期呼び出しを実行できず、ssl を操作できないことがほのめかされている別のstackoverflow の投稿が見つかるまで、私は Web を検索しました(ssl 認証プロセスを処理するデリゲートがないため)。私がやったことは、ASIHTTPRequestを取得してそれを使用することです。それは簡単で、セットアップに約1時間かかり、完璧に機能しました. これが私がそれを使用する方法です。
+ (NSString *) getSynchronously:(NSDictionary *)parameters {
NSURL *url = [NSURL URLWithString:@"https://localhost:8443/MyApp/";
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
NSString *parameterJSONString = [parameters JSONRepresentation];
[request appendPostString:parameterJSONString];
[request addRequestHeader:@"User-Agent" value:@"MyAgent"];
request.timeOutSeconds = CONNECTION_TIME_OUT_INTERVAL;
[request setValidatesSecureCertificate:NO];
[request startSynchronous];
NSString *responseString = [request responseString];
if (request.error) {
NSLog(@"Server connection failed: %@", [request.error localizedDescription]);
} else {
NSLog(@"Server response: %@", responseString);
}
return responseString;
}
もちろん重要な部分は、
[request setValidatesSecureCertificate:NO];
もう 1 つの方法は、上記の 2 つの方法を使用して非同期接続を使用して別のスレッドでダウンロードを処理し、要求が完了するまで同期接続が必要なスレッドをブロックすることです。