ios9 HTTP加载失败kCFStreamErrorDomainSSL(-9802)
我有一个最近出现的问题。
在我的代码中,我从HTTP服务器加载一些图像:
let urlPicture = "http://images.mydomain.com/" + self.currentUser.pic imageView.sd_setImageWithURL(NSURL(string: urlPicture))
我不使用HTTPS为我的图像服务器,因为我猜它会太慢,但也许我在这一点上是错误的。 nodejs服务器正在AWS EC2实例中运行,并侦听端口80以pipe理映像。
由于ATS限制,我在Info.plist文件中为我的图像子域声明了一个exception:
<key>NSAppTransportSecurity</key> <dict> <key>NSExceptionDomains</key> <dict> <key>images.mydomain.com</key> <dict> <key>NSExceptionAllowsInsecureHTTPLoads</key> <true/> <key>NSExceptionMinimumTLSVersion</key> <string>TLSv1.2</string> <key>NSExceptionRequiresForwardSecrecy</key> <true/> <key>NSIncludesSubdomains</key> <true/> <key>NSRequiresCertificateTransparency</key> <false/> <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key> <false/> <key>NSThirdPartyExceptionMinimumTLSVersion</key> <string>TLSv1.2</string> <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <true/> </dict> </dict> </dict>
最近,我在同一个 AWS实例上添加了一个新的子域: https ://api.mydomain.com另一个nodejs服务器在443端口上侦听并pipe理API。
由于这个改变,当我调用API时,在我的应用程序中一切正常,但是当我加载图像时,我面临以下问题:
NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)
任何想法解决这个问题?
我发现这个问题。
在服务器端,运行在同一个AWS实例上的HTTPS服务器configuration了HSTS:
var ONE_YEAR = 31536000000; app.use(helmet.hsts({ maxAge: ONE_YEAR, includeSubdomains: true, force: true }));
设置为true
的variablesincludeSubdomains
强制我的其他域images.mydomain.com
使用HTTPS协议,而它是一个HTTP服务器。
要解决这个问题,只需排除其他域在HSTSconfiguration:
var ONE_YEAR = 31536000000; app.use(helmet.hsts({ maxAge: ONE_YEAR, includeSubdomains: false, force: true }));
你可以加上这个plist。
<key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict>