xcode iOS 11:发生 SSL 错误,无法连接到服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49360954/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iOS 11 : SSL error occurred and connection to server cannot be made
提问by Jayprakash Dubey
When I'm trying to connect with Server (which is IIS)
I'm getting below error on console window :
当我尝试连接时Server (which is IIS)
,控制台窗口出现以下错误:
API error: An SSL error has occurred and a secure connection to the server cannot be made.and hence not able to login.
API 错误:发生 SSL 错误,无法与服务器建立安全连接。因此无法登录。
I'm using Xcode 9.2, iOS 11.
我使用的是 Xcode 9.2,iOS 11。
Below are solutions that I've tried but didn't worked :
以下是我尝试过但没有奏效的解决方案:
App Transport Security Settings
->Allow Arbitrary Loads
->YES
Add exception domain
etc.Troubleshoot IIS along with server team and figured out that it is not secured i.e. no HTTPS or SSL
App Transport Security Settings
->Allow Arbitrary Loads
->YES
Add exception domain
等等。与服务器团队一起对 IIS 进行故障排除,并发现它不安全,即没有 HTTPS 或 SSL
This is my plist ATS configuration
这是我的 plist ATS 配置
P.S. This project is written in Objective-C back in 2014 by third party vendor. Does this issue is due to Objective-C language? (well I don't think so)
PS 这个项目是由第三方供应商在 2014 年用 Objective-C 编写的。这个问题是否是由于 Objective-C 语言造成的?(好吧,我不这么认为)
Any Fix?
任何修复?
采纳答案by wottle
Judging by the screenshot, it appears you might be using a .dev domain. If so, you will not be able to disable ATS because Google owns the .dev domain, and they have chosen to require all .dev domains require HTTPS. In iOS 11, Apple supports HSTS preloading, which allows certain domains to be restricted to secure connection only. The .dev top-level domain (TLD) is now one of those TLDs that require HTTPS. See more about that here: https://stackoverflow.com/a/47698675/3708242
从屏幕截图来看,您可能正在使用 .dev 域。如果是这样,您将无法禁用 ATS,因为 Google 拥有 .dev 域,并且他们已选择要求所有 .dev 域都需要 HTTPS。在 iOS 11 中,Apple 支持 HSTS 预加载,它允许某些域仅限于安全连接。.dev 顶级域 (TLD) 现在是需要 HTTPS 的那些 TLD 之一。在此处查看更多相关信息:https: //stackoverflow.com/a/47698675/3708242
You screenshot includes an ATS exception that ends in .dev, but your comments specify a different domain. I'm assuming that maybe there are multiple exceptions in your Info.plist, and you use the .dev for internal testing against a local server. If that is the case, simply change the domain for your internal testing to something other than *.dev
. Also, not that the exception in your screenshot is not correct, as it includes http:// in the exception domain. Instead of an entry in the InfoPlist like "http://mylocalserver.local", you should just have "mylocalserver.local" (no http://).
您的屏幕截图包含以 .dev 结尾的 ATS 异常,但您的评论指定了不同的域。我假设您的 Info.plist 中可能存在多个异常,并且您使用 .dev 对本地服务器进行内部测试。如果是这种情况,只需将内部测试的域更改为*.dev
. 此外,并不是说屏幕截图中的异常不正确,因为它在异常域中包含 http://。而不是 InfoPlist 中的条目,如“ http://mylocalserver.local”,您应该只有“mylocalserver.local”(没有 http://)。
If your entry for abc.pqr.lmn
is the same (it also includes the protocol in the exception domain), remove the "http://" and it should work.
如果您的条目abc.pqr.lmn
相同(它还包括异常域中的协议),请删除“http://”,它应该可以工作。
Also, your exceptions list is a bit of a mess. If you are not using https at all, you should be able to remove all the entries except for NSExceptionAllowsInsecureLoads
. All the other settings you specify are for if you want to allow for HTTPS connections that don't support the minimum requirements for ATS. If you are just trying to non-secure HTTP traffic, get rid of the others.
此外,您的例外列表有点混乱。如果您根本不使用 https,您应该能够删除除NSExceptionAllowsInsecureLoads
. 如果您希望允许不支持 ATS 最低要求的 HTTPS 连接,则您指定的所有其他设置都适用。如果您只是想保护 HTTP 流量,请摆脱其他人。
So in summary:
所以总结一下:
- Don't use a .dev domain for local testing, as Google owns the top-level domain now and requires all new browsers / OSs to use HTTPS when connecting to anything that ends in .dev.
- Don't include "http://" in your ATS exception domains in your Info.plist
- It doesn't have anything to do with it being in Objective-C - it has to do with iOS 11 implementing HSTS preloading.
- 不要使用 .dev 域进行本地测试,因为 Google 现在拥有顶级域,并且要求所有新浏览器/操作系统在连接到任何以 .dev 结尾的内容时都使用 HTTPS。
- 不要在 Info.plist 的 ATS 例外域中包含“http://”
- 这与它在 Objective-C 中没有任何关系 - 它与实现 HSTS 预加载的 iOS 11 有关。