简体   繁体   English

NSURLSession/NSURLConnection HTTP 加载在 iOS 9 上失败

[英]NSURLSession/NSURLConnection HTTP load failed on iOS 9

Tried to run my existing app on iOS9 but getting failure while using AFURLSessionManager .试图在 iOS9 上运行我现有的应用程序,但在使用AFURLSessionManager失败。

__block NSURLSessionDataTask *task = [self.sessionManager dataTaskWithRequest:request completionHandler:^(NSURLResponse * __unused response, id responseObject, NSError *error) {
    if (error) {

    } else {

    }
}];

[task resume];

I get the following error:我收到以下错误:

Error Domain=NSURLErrorDomain Code=-999 "cancelled.

Also getting following logs:还得到以下日志:

 NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9824
 CFNetwork SSLHandshake failed (-9824)

Update: I have added multiple updates to my solution: NSURLSession/NSURLConnection HTTP load failed on iOS 9更新:我为我的解决方案添加了多个更新: iOS 9 上的 NSURLSession/NSURLConnection HTTP 加载失败

Found solution:找到解决方案:

In iOS9, ATS enforces best practices during network calls, including the use of HTTPS.在 iOS9 中,ATS 在网络调用期间强制执行最佳实践,包括使用 HTTPS。

From Apple documentation: 来自苹果文档:

ATS prevents accidental disclosure, provides secure default behavior, and is easy to adopt. ATS 可防止意外泄露,提供安全的默认行为,并且易于采用。 You should adopt ATS as soon as possible, regardless of whether you're creating a new app or updating an existing one.无论您是创建新应用还是更新现有应用,都应尽快采用 ATS。 If you're developing a new app, you should use HTTPS exclusively.如果您正在开发新应用程序,则应专门使用 HTTPS。 If you have an existing app, you should use HTTPS as much as you can right now, and create a plan for migrating the rest of your app as soon as possible.如果你有一个现有的应用程序,你现在应该尽可能多地使用 HTTPS,并尽快制定迁移应用程序其余部分的计划。

In beta 1, currently there is no way to define this in info.plist.在 beta 1 中,目前无法在 info.plist 中定义它。 Solution is to add it manually:解决方法是手动添加:

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

在此处输入图片说明

Update1: This is a temporary workaround until you're ready to adopt iOS9 ATS support.更新 1:这是一个临时解决方法,直到您准备好采用 iOS9 ATS 支持。

Update2: For more details please refer following link: http://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/ Update2:更多详情请参考以下链接: http : //ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/

Update3: If you are trying to connect to a host (YOURHOST.COM) that only has TLS 1.0更新 3:如果您尝试连接到只有 TLS 1.0 的主机 (YOURHOST.COM)

Add these to your app's Info.plist将这些添加到您的应用程序的 Info.plist

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>YOURHOST.COM</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSTemporaryExceptionMinimumTLSVersion</key>
            <string>1.0</string>
            <key>NSTemporaryExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
    </dict>
</dict>

How to deal with the SSL in iOS9,One solution is to do like:如何处理iOS9中的SSL,一个解决方案是这样做:

As the Apple say :正如苹果所说: 在此处输入图片说明在此处输入图片说明

在此处输入图片说明

iOS 9 and OSX 10.11 require TLSv1.2 SSL for all hosts you plan to request data from unless you specify exception domains in your app's Info.plist file. iOS 9 和 OSX 10.11 要求您计划从中请求数据的所有主机都使用 TLSv1.2 SSL,除非您在应用程序的 Info.plist 文件中指定异常域。

The syntax for the Info.plist configuration looks like this: Info.plist 配置的语法如下所示:

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
    <key>yourserver.com</key>
    <dict>
      <!--Include to allow subdomains-->
      <key>NSIncludesSubdomains</key>
      <true/>
      <!--Include to allow insecure HTTP requests-->
      <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
      <true/>
      <!--Include to specify minimum TLS version-->
      <key>NSTemporaryExceptionMinimumTLSVersion</key>
      <string>TLSv1.1</string>
    </dict>
  </dict>
</dict>

If your application (a third-party web browser, for instance) needs to connect to arbitrary hosts, you can configure it like this:如果您的应用程序(例如第三方 Web 浏览器)需要连接到任意主机,您可以像这样配置它:

<key>NSAppTransportSecurity</key>
<dict>
    <!--Connect to anything (this is probably BAD)-->
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

If you're having to do this, it's probably best to update your servers to use TLSv1.2 and SSL, if they're not already doing so.如果您必须这样做,最好更新您的服务器以使用 TLSv1.2 和 SSL,如果他们还没有这样做的话。 This should be considered a temporary workaround.这应被视为一种临时解决方法。

As of today, the prerelease documentation makes no mention of any of these configuration options in any specific way.截至今天,预发布文档未以任何特定方式提及任何这些配置选项。 Once it does, I'll update the answer to link to the relevant documentation.一旦完成,我将更新答案以链接到相关文档。

For more info ,go to iOS9AdaptationTips有关更多信息,请访问iOS9AdaptationTips

Apple's Technote on App Transport Security is very handy ; Apple 关于 App Transport Security 的 Technote 非常方便 it helped us find a more secure solution to our issue.它帮助我们找到了更安全的解决方案。

Hopefully this will help someone else.希望这会帮助别人。 We were having issues connecting to Amazon S3 URLs that appeared to be perfectly valid, TLSv12 HTTPS URLs.我们在连接到似乎完全有效的 Amazon S3 URL TLSv12 HTTPS URL 时遇到问题。 Turns out we had to disable NSExceptionRequiresForwardSecrecy to enable another handful of ciphers that S3 uses.事实证明,我们必须禁用NSExceptionRequiresForwardSecrecy才能启用 S3 使用的另一些密码。

In our Info.plist :在我们的Info.plist

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
    <key>amazonaws.com</key>
    <dict>
      <key>NSIncludesSubdomains</key>
      <true/>
      <key>NSExceptionRequiresForwardSecrecy</key>
      <false/>
    </dict>
  </dict>
</dict>

If you're having this problem with Amazon S3 as me, try to paste this on your info.plist as a direct child of your top level tag如果您和我一样在使用 Amazon S3 时遇到此问题,请尝试将其粘贴到您的 info.plist 中作为您的顶级标签的直接子项

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>amazonaws.com</key>
        <dict>
              <key>NSThirdPartyExceptionMinimumTLSVersion</key>
              <string>TLSv1.0</string>
              <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
              <false/>
              <key>NSIncludesSubdomains</key>
              <true/>
        </dict>
        <key>amazonaws.com.cn</key>
        <dict>
              <key>NSThirdPartyExceptionMinimumTLSVersion</key>
              <string>TLSv1.0</string>
              <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
              <false/>
              <key>NSIncludesSubdomains</key>
              <true/>
        </dict>
    </dict>
</dict>

You can find more info at:您可以在以下位置找到更多信息:

http://docs.aws.amazon.com/mobile/sdkforios/developerguide/ats.html#resolving-the-issue http://docs.aws.amazon.com/mobile/sdkforios/developerguide/ats.html#resolving-the-issue

I found solution from here.我从这里找到了解决方案 And its working for me.它对我有用。

Check this, it may help you.检查这个,它可能会帮助你。

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
         <dict>
             <key>myDomain.com</key>
                    <dict>
                      <!--Include to allow subdomains-->
                      <key>NSIncludesSubdomains</key>
                      <true/>
                      <!--Include to allow HTTP requests-->
                      <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
                      <true/>
                      <!--Include to specify minimum TLS version-->
                      <key>NSTemporaryExceptionMinimumTLSVersion</key>
                      <string>TLSv1.1</string>
                </dict>
          </dict>
</dict>

Simply add the following fields in your .plist file只需在 .plist 文件中添加以下字段

在此处输入图片说明

Syntax looks like this:语法如下所示:

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

Update:更新:

As of Xcode 7.1, you don't need to manually enter the NSAppTransportSecurity Dictionary in the info.plist .从 Xcode 7.1 开始,您无需在info.plist手动输入NSAppTransportSecurity字典。

It will now autocomplete for you, realize it's a dictionary, and then autocomplete the Allows Arbitrary Loads as well.它现在会为您自动完成,意识到它是一个字典,然后自动完成Allows Arbitrary加载。 info.plist screenshot info.plist 截图

Solve NSURLConnection Http load failed bug Just Add following Dict in info.plist:解决 NSURLConnection Http load failed bug 只需在 info.plist 中添加以下 Dict:

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

I have solved it with adding some key in info.plist.我已经通过在 info.plist 中添加一些键来解决它。 The steps I followed are:我遵循的步骤是:

I Opened my project's info.plist file我打开了我项目的 info.plist 文件

Added a Key called NSAppTransportSecurity as a Dictionary.添加了一个名为 NSAppTransportSecurity 的 Key 作为字典。

Added a Subkey called NSAllowsArbitraryLoads as Boolean and set its value to YES as like following image.将名为 NSAllowsArbitraryLoads 的子项添加为布尔值,并将其值设置为 YES,如下图所示。 enter image description here在此处输入图片说明

Clean the Project and Now Everything is Running fine as like before.清理项目,现在一切都像以前一样运行良好。

Ref Link: https://stackoverflow.com/a/32609970参考链接: https : //stackoverflow.com/a/32609970

This is what worked for me when I had this error:当我遇到此错误时,这对我有用:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>example.com</key>
        <dict>
            <key>NSExceptionRequiresForwardSecrecy</key>
            <false/>
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSTemporaryExceptionMinimumTLSVersion</key>
            <string>TLSv1.0</string>
        </dict>
    </dict>
</dict>

您可以尝试在文件 RCTHTTPRequestHandler.m 中添加此功能

- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler { completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]); }

除了上面提到的答案,重新检查你的网址

You should add App Transport Security Settings to info.plist and add Allow Arbitrary Loads to App Transport Security Settings您应该将App Transport Security Settings添加到info.plist并将Allow Arbitrary Loads添加到App Transport Security Settings

在此处输入图片说明

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NSURLSession/NSURLConnection HTTP 加载失败以及 iOS 9 的其他 AdMob 警告 - NSURLSession/NSURLConnection HTTP load failed and other AdMob warnings for iOS 9 iOS 9中的HTTPS请求:NSURLSession / NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9802) - HTTPS request in iOS 9 : NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802) 使用Xcode 7.1的iOS 9中的NSURLSession / NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9813) - NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813) in iOS 9 with Xcode 7.1 在iOS 9中NSURLSession / NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9802) - NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802) in ios 9 NSURLSession/NSURLConnection HTTP 加载在设备 9.0 上失败 - NSURLSession/NSURLConnection HTTP load failed on device 9.0 NSURLSession / NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9813) - NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813) NSURLSession/NSURLConnection HTTP 加载在 Swift 4 上失败 - NSURLSession/NSURLConnection HTTP load failed on Swift 4 NSURLSession / NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9814) - NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9814) Swift / https:NSURLSession / NSURLConnection HTTP加载失败 - Swift/https: NSURLSession/NSURLConnection HTTP load failed iOS 10.2 Firebase / Admob集成 - NSURLSession / NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9814) - iOS 10.2 Firebase/Admob Integration - NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9814)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM