OGeek|极客世界-中国程序员成长平台

标题: iOS:遇到错误 kCFURLErrorUserCancelledAuthentication -1012? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 10:49
标题: iOS:遇到错误 kCFURLErrorUserCancelledAuthentication -1012?

在 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 enqueueOperationp];   
}

我做错了什么?

附言

Certificate,即尝试签名请求已提前收到。在浏览器中单独测试,没问题。

一个应用程序对同一服务器的请求通常是相同的方案。



Best Answer-推荐答案


当您的连接发送身份验证质询请求时,可能会发生这种情况。

可能的原因是网站的证书无效/不受信任,而您选择不接受无效证书。

关于iOS:遇到错误 kCFURLErrorUserCancelledAuthentication -1012?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24785539/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4