Ios 带有自签名证书的https url上的webService请求不';不行?

Ios 带有自签名证书的https url上的webService请求不';不行?,ios,objective-c,web-services,https,nsurlsession,Ios,Objective C,Web Services,Https,Nsurlsession,我试图使用NSURLSession和NSURLSessionDataTask调用web服务,该站点是一个HTTPS,使用自签名证书,我试图为NSURLSession设置委托并调用其方法以允许请求继续,但它也不起作用 我还在Info.plist中设置了应用程序传输安全性,但它也不起作用,而且它仅用于测试目的,我知道使用自签名证书很危险,请提供帮助 以下是调用Web服务的示例代码: - (void) operationRequest{ NSMutableArray *extraDataReq

我试图使用
NSURLSession
NSURLSessionDataTask
调用web服务,该站点是一个
HTTPS
,使用自签名证书,我试图为
NSURLSession
设置委托并调用其方法以允许请求继续,但它也不起作用

我还在
Info.plist
中设置了应用程序传输安全性,但它也不起作用,而且它仅用于测试目的,我知道使用自签名证书很危险,请提供帮助

以下是调用Web服务的示例代码:

- (void) operationRequest{
    NSMutableArray *extraDataRequest = [[NSMutableArray alloc] init];
    [extraDataRequest addObject:[mPayRequest prepareExtraDataWithKey:systemConstantsObj.section andValue:@"Dinarak"]];

    NSNumber *defaultLanguage = [NSNumber numberWithInt:1];
    NSDictionary *newDatasetInfo = [mPayRequest mPayRequestJsonObject:deviceId extraData:extraDataRequest language:defaultLanguage operation:systemConstantsObj.systemConfiguration pinCode:[NSNull null] sender:deviceId senderType:systemConstantsObj.mobileSenderType];

    NSString *stringValues = [mPayRequest ToStringValues:deviceId extraData:extraDataRequest language:defaultLanguage operation:systemConstantsObj.systemConfiguration pinCode:[NSNull null] sender:deviceId senderType:systemConstantsObj.mobileSenderType];

    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
    NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:[NSOperationQueue mainQueue]];
    NSMutableURLRequest *request = [WebService POST:stringValues initWithJsonString:newDatasetInfo];

    NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error){
        if (data != nil && error == nil) {
            [self parseResponse:data];
        }
        if (data == nil || error != nil) {
            NSLog(@"error %@", error);
        }
    }];

    [dataTask resume];
}

-(void)parseResponse:(NSData *)data{
    NSMutableArray *extraData = [mPayResponseResult parseResponseForOperation:systemConstantsObj.systemConfiguration withData:data];
    if (extraData != nil && [extraData count] > 0)
        [systemConstantsObj saveSystemConfigurations:extraData];
    else
        systemConstantsObj.systemConfigsList = nil;
}

- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler{
    if([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]){
        if([challenge.protectionSpace.host isEqualToString:@"dinarakapp"]){
            NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
            completionHandler(NSURLSessionAuthChallengeUseCredential,credential);
        }
    }
}

- (BOOL)connection:(NSURLSession *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
    return YES;
}

- (void)connection:(NSURLSession *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
    if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
    [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
        if([challenge.protectionSpace.host isEqualToString:@"dinarakapp"])
            [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];

    [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
以及
Info.plist
的设置:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>https://80.90.171.183:8445/ps-mpay</key>
        <dict>
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSAllowsArbitraryLoads</key>
            <true/>
        </dict>
    </dict>
</dict>
NSAppTransportSecurity
NSExceptionDomains
https://80.90.171.183:8445/ps-姆贝
NSTemporary ExceptionalLowsInSecureHttpLoads
n包括多个域
NSAllowsArbitraryLoads

在主项目文件夹和项目测试文件夹的Info.plist中添加以下代码。我们以前也有过同样的问题。通过在主项目Info.plist中添加AppTransportSecurity,我们得到了相同的错误。当我们在Info.plist文件中进行更改时,它起作用了

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>
NSAppTransportSecurity
NSAllowsArbitraryLoads

在主项目文件夹和项目测试文件夹的Info.plist中添加以下代码。我们以前也有过同样的问题。通过在主项目Info.plist中添加AppTransportSecurity,我们得到了相同的错误。当我们在Info.plist文件中进行更改时,它起作用了

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>
NSAppTransportSecurity
NSAllowsArbitraryLoads

harsha yarabarla不幸的是,它也无法工作。NSURLSession/NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9802)错误域=NSURErrorDomain code=-1200“发生SSL错误,无法与服务器建立安全连接。”UserInfo={nsurlerErrorFailingUrlPeertRusterErrorKey=,NSLocalizedRecoverySuggestion=是否仍要连接到服务器?,kCFStreamErrorDomainKey=3,kCFStreamErrorCodeKey=-9802,NSErrorPeerCertificateChainKey={type=immutable,count=1,value=(0:)},NSUnderlyingError=0x15ed2ac40{Error Domain=kcforDomain=kcforDomain=kcforDomain=-1200”(null)UserInfo={{kCFStreamPropertySSLClientCertificateState=1,kCFStreamPropertySSLPeerTrust=,{KCFnetworkCfStreamsSrorOriginalValue=-9802,{kCFStreamErrorDomainKey=3,{kCFStreamErrorCodeKey=-9802,kCFStreamPropertySSLPeerCertificates={type=不可变,计数=1,值=(0:)}},NSLocalizedDescription=发生SSL错误,无法与服务器建立安全连接:harsha yarabarla很遗憾,它也无法工作。NSURLSession/NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9802)错误域=NSURerrorDomain代码=-1200“发生SSL错误,无法与服务器建立安全连接。”UserInfo={NSURlerErrorFailingUrlPeerTrustErrorKey=,NSLocalizedRecoverySuggestion=是否仍要连接到服务器?,kCFStreamErrorDomainKey=3,kCFStreamErrorCodeKey=-9802,NSErrorPeerCertificateChaineKey={type=immutable,count=1,Value=(0:)},NSUnderlyingError=0x15ed2ac40{Error Domain=kCFErrorDomainCFNetwork Code=-1200“(null)”用户信息={{kCFStreamPropertySSLClientCertificateState=1,kCFStreamPropertySSLPeerTrust=,KCFnetworkCfStreamsSlorOriginalValue=-9802,kCFStreamErrorDomainKey=3,kCFStreamErrorCodeKey=-9802,kCFStreamPropertySSLPeerCertificates={type=immutable,count=1,values=(0:)}}},NSLocalizedDescription=发生SSL错误,无法与服务器建立安全连接:任何解决方案人员?任何解决方案人员?