在 iOS 应用程序中,需要签署之前已获得的证书请求。当我尝试运行查询时捕获此错误:
kCFURLErrorUserCancelledAuthentication -1012.
文档说:
kCFURLErrorUserCancelledAuthentication The connection failed because the user cancelled required authentication.
实现如下:
- (void)startConnection {
NSString *serverURL = @"host.ru/method";
MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:serverURL customHeaderFields:nil];
MKNetworkOperation *op = [engine operationWithPath:nil params:nil httpMethod:@"GET" ssl:YES];
NSString *thePath = [[NSBundle mainBundle] pathForResource:@"client" ofType:@"p12"];
[op setShouldContinueWithInvalidCertificate:YES];
op.clientCertificate = thePath;
op.clientCertificatePassword = @"1234qwerty";
[op addCompletionHandler:^(MKNetworkOperation *operation) {
NSLog(@"[operation responseData]-->>%@", [operation responseString]);
}errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
}];
[engine enqueueOperation:op];
}
我做错了什么?
附注
已提前收到尝试签署请求的证书。在浏览器中单独测试,没问题。
Android应用程序向同一服务器发出的请求通常都是相同的方案。
最佳答案
当您的连接发送身份验证质询请求时,可能会发生这种情况。
可能的原因是该网站的证书无效/不受信任,并且您选择不接受无效证书。
关于iOS:遇到错误 kCFURLErrorUserCancelledAuthentication -1012?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24785539/