我想向有 SSL 问题的 Web 服务发布一些内容。我使用了以下方法:
NSURLConnection * urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
它应该立即开始发送已在请求中设置的数据;但服务存在安全问题,无法正常工作。但是我想发送数据并想忽略安全问题;所以我使用了以下 NSURLConnectionDelegate 方法:
- (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];
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
但它们已被弃用。如何处理安全问题并告诉将数据传递给 Web 服务而不考虑它?