【问题标题】:POST Value getting error in ios 9 (NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)POST 值在 ios 9 中出现错误(NSURLSession/NSURLConnection HTTP 加载失败(kCFStreamErrorDomainSSL,-9813)
【发布时间】:2016-02-24 06:28:07
【问题描述】:

我尝试使用这些代码,但只收到类似的错误消息

错误消息:-NSURLSession/NSURLConnection HTTP 加载失败(kCFStreamErrorDomainSSL,-9813

网址:-http://www.xxxxx.com/XXX/rest/files/downloadFile/en/linto/

Header:- Content-Type: application/x-www-form-urlencoded

RAW:- phoneNumber=%2B15163120019&uname=test

响应头:服务器:Apache-Coyote/1.1

内容类型:文本/xml

传输编码:分块

日期:格林威治标准时间 2016 年 2 月 24 日星期三 05:03:05 生的 已解析

XCODE 版本:7.2.1 我的代码:-

NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: nil delegateQueue: [NSOperationQueue mainQueue]];

NSURL * url = [NSURL URLWithString:@"https://www.indusaudio.com/WeeAudio/rest/files/downloadFile/en/linto/"];
NSMutableURLRequest * urlRequest = [NSMutableURLRequest requestWithURL:url];
[urlRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
NSString * params =@"phoneNumber=%2B15163120019&uname=test";

[urlRequest setHTTPBody:[params dataUsingEncoding:NSUTF8StringEncoding]];
[urlRequest setHTTPMethod:@"POST"];

NSURLSessionDataTask * dataTask =[defaultSession dataTaskWithRequest:urlRequest
                                                   completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                       NSLog(@"Response:%@ %@\n", response, error);
                                                       if(error == nil)
                                                       {
                                                          // NSString * text = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
                                                           //NSLog(@"Data = %@",text);
                                                       }

                                                   }];
[dataTask resume];

}

【问题讨论】:

    标签: ios objective-c xcode post


    【解决方案1】:

    试着写这行不带斜线

    NSURL * url = [NSURL URLWithString:@"https://www.indusaudio.com/WeeAudio/rest/files/downloadFile/en/linto/"];
    

    NSURL * url = [NSURL URLWithString:@"http://www.indusaudio.com/WeeAudio/rest/files/downloadFile/en/linto/"];
    

    【讨论】:

    • 你的服务器有问题,请去爸爸支持。谢谢
    • 如果我喜欢没有斜线,我会收到这样的消息。
    • Response:(null) Error Domain=NSURLErrorDomain Code=-1202 "该服务器的证书无效。您可能正在连接一个伪装成“www.indusaudio.com”的服务器可能会使您的机密信息面临风险。” UserInfo={NSURLErrorFailingURLPeerTrustErrorKey=, NSLocalizedRecoverySuggestion=您还是要连接到服务器吗?, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9813, NSErrorPeerCertificateChainKey=
    • 我发现了问题,请在您的 URL 中使用 http 代替 https
    • @lintojacob 请支持我的回答
    【解决方案2】:

    iOS9 要求服务器仅支持 TLSv1.2,必须在应用 plist 中添加异常才能解决。

    将此密钥添加到您的.plist

    <key>NSAppTransportSecurity</key>
    <dict>
      <!--Include to allow all connections (DANGER)-->
      <key>NSAllowsArbitraryLoads</key>
          <true/>
    </dict>
    

    Steven Peterson's Blog 上查看更多信息。

    【讨论】:

      猜你喜欢
      • 2016-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-29
      • 2016-11-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多