微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

NSURLConnection / CFURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9813)iOS

目前我正在使用ios中的一个soap网页服务,我的源代码如下
Nsstring *xml = requestXMLToSent;

Nsstring *msgLength = [Nsstring stringWithFormat:@"%lu",(unsigned long)[xml length]];
NSURL *serviceURL = [NSURL URLWithString: url];
NSMutableuRLRequest *urlRequest = [NSMutableuRLRequest requestWithURL:serviceURL];

[urlRequest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[urlRequest addValue: serviceURL forHTTPHeaderField:@"SOAPAction"];
[urlRequest addValue:msgLength  forHTTPHeaderField:@"Content-Length"];
[urlRequest setHTTPBody: [xml dataUsingEncoding:NSUTF8StringEncoding]];
[urlRequest setHTTPMethod:@"POST"];

[NSURLConnection sendAsynchronousRequest:urlRequest queue:[[NSOperationQueue alloc]init] completionHandler:^(NSURLResponse *response,NSData *data,NSError *connectionError) {


    if (connectionError == NULL) {

        NSHTTPURLResponse * httpResponse = (NSHTTPURLResponse *) response;
        NSInteger statuscode = httpResponse.statusCode;
        if (statuscode == 200) {

            Nsstring *responseString = [[Nsstring alloc] initWithData:data encoding:NSUTF8StringEncoding];
            NSLog(@"response String  : %@",responseString);


        }else{
            NSLog(@"%@",response);

        }




    }else{

        NSLog(@"There is an error in URL connection and the Error is : %@",connectionError);
    }

我收到以下错误@控制台

NSURLConnection/CFURLConnection HTTP load Failed (kcfStreamErrorDomainSSL,-9813)

URL连接出现错误,错误是:Error Domain = NSURLErrorDomain Code = -1202“此服务器的证书无效,您可能会连接到假装为”www.xxxxxxxx.net“的服务器,该服务器可能将您的机密信息置于危险之中.“ UserInfo = 0x10948bbb0 {NSUnderlyingError = 0x109470d10“该服务器的证书无效,您可能会连接到假冒为”www.xxxxxx.net“的服务器,这可能会使您的机密信息处于危险之中.”NSErrorFailingURLStringKey = https: // www .———————————-,NSErrorFailingURLKey = https:// —– ——————– NSLocalizedRecoverySuggestion =是否要连接到服务器?NSURLErrorFailingURLPeerTrustErrorKey =,NSLocalizedDescription =此服务器的证书无效.您可能会连接到假装为“www.xxxxxx.net”的服务器,这可能会使您的机密信息面临风险.

解决方法

服务器正在抛出SSL证书错误.
为了测试,您可以将以下代码添加到appDelegate中:

(BOOL)allowAnyHTTPSCertificateForHost

原文地址:https://www.jb51.cc/java/123926.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐