【发布时间】:2015-10-09 10:44:53
【问题描述】:
我正在使用NSURLConnection 连接https api 并且服务器正在使用
"Go Daddy Certificate Authority - G2" and "is encrypted using a modern cipher suite.
The connection uses TLS 1.2.
The connection is encrypted and authenticated using AES_128_GCM and uses ECDHE_RSA as the key exchange mechanism."
我已经实现了以下代表
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
[[challenge sender] useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
}
但问题是“没有一个委托方法正在命中”。为什么身份验证方法没有命中以及如何解决?
在实现文件中使用如下@interface classname () < NSURLConnectionDelegate, UIAlertViewDelegate >
而 NSURLConnection Delegate 直接点击下面的方法- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
NSURLConnection代码如下
NSURL *url = [NSURL URLWithString:@"urlString"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request addValue:postLength forHTTPHeaderField:@"Content-Length"];
[request addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Accept"];
[request addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"v1.1" forHTTPHeaderField:@"Version"];
[request setHTTPBody:postData];
DLog(@"%@\n%@\n%@", request, request.allHTTPHeaderFields, [[NSString alloc] initWithData:request.HTTPBody encoding:NSUTF8StringEncoding]);
self.responseData = [[NSMutableData alloc] init];
// send the login request
self.loginConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO];
[self.loginConnection scheduleInRunLoop:[NSRunLoop mainRunLoop]
forMode:NSDefaultRunLoopMode];
[self.loginConnection start];
【问题讨论】:
-
您的 xcode 版本是 Xcode 7 吗?
-
感谢回复,xcode版本是6.4
标签: ios security https aes rsa