NSURLSession "HTTP 加载失败 kCFStreamErrorDomainSSL, -9813 ;自签名证书 [英] NSURLSession "HTTP load failed kCFStreamErrorDomainSSL, -9813 ; Self signing certificate
问题描述
我正在尝试将我的 iOS 应用程序连接到当前在我网络中的本地主机上运行的 HTTPS Rails 应用程序.我可以使用 https://myIP:3000/display
从我的浏览器访问该站点,也可以使用 curl 请求在命令行中访问该站点.我正在尝试使用以下方法从我的应用程序访问它:
class FirstViewController: UIViewController {覆盖 func viewDidLoad() {super.viewDidLoad()//让 url = NSURL(string: "https://another/Sinatra/website/feed")让 url = NSURL(string: "https://myIP:3000/display")让请求 = NSURLRequest(URL: url!)让任务 = NSURLSession.sharedSession().dataTaskWithURL(url!)任务!.resume()}
当我尝试访问 sinatra 网站时,我没有问题,甚至可以使用正确的命令将 JSON 打印到控制台.但是,当我将 url 设置为 Rails 网站时,出现以下错误.
<块引用>NSURLSession/NSURLConnection HTTP 加载失败 (kCFStreamErrorDomainSSL, -9813)
此外,我可以看出我的 localhost Rails 应用程序(在另一台机器上)不是从 iOS 应用程序 ping 的,而是从浏览器和 curl 命令 ping 的.
有什么想法可以解决这个问题吗?
如果我理解得很好,Apple 现在希望开发人员使用 HTTPS 和 TLS 1.2 进行网络调用.
临时,您可以将其添加到Info.plist"文件中:
NSAppTransportSecurity <字典><key>NSAllowsArbitraryLoads</key><真/></dict>
看看这个链接,它也可以帮助你:
-
否则你可以设置Domain Exceptions
.这是怎么做的:
- 转到您的
Info.plist
文件. - 添加一行 Type
Dictionary
和 KeyApp Transport Security Settings
. - 添加一行 Type
Dictionary
和 KeyException Domains
. - 添加一行Type
Dictionary
和Key域
. - 添加两行 Type
Boolean
和 KeyNSExceptionAllowsInsecureHTTPLoads
&NSIncludesSubdomains
将 Value 设为YES
.
链接
https://forums.developer.apple.com/message/5857#5857
iOS 9 HTTP 连接错误 - StackOverflow
I'm trying to connect my iOS app to an HTTPS Rails app which is currently run on a local host in my network. I can access the site from my browser with https://myIP:3000/display
as well as in the command line with a curl request. I'm trying to access it from my app using:
class FirstViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
//let url = NSURL(string: "https://another/Sinatra/website/feed")
let url = NSURL(string: "https://myIP:3000/display")
let request = NSURLRequest(URL: url!)
let task = NSURLSession.sharedSession().dataTaskWithURL(url!)
task!.resume()
}
When I try to access the sinatra website I have no trouble and can even print out the JSON to the console with the correct commands. However, when I set url to my Rails website I get the following error.
NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)
In addition, I can tell that my localhost Rails app (on the other machine) is not pinged from the iOS app, but is pinged from the browser and curl command.
Any ideas how to fix this?
If I understood well, Apple now wants the developers to use HTTPS and TLS 1.2 for network calls.
Temporary, you can add this in your "Info.plist" file :
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Just have a look to this link, it may also help you : http://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/
--
Update : Following some comments the above solution is not anymore working. Here is an updated solution.
- Go to your
Info.plist
file. - Add a row of Type
Dictionary
and of KeyApp Transport Security Settings
. - In this Dictionary, add a row of Type
Boolean
, of KeyAllow Arbitrary Loads
and of ValueYES
-
Otherwise you can set Domain Exceptions
. This is how to do :
- Go to your
Info.plist
file. - Add a row of Type
Dictionary
and of KeyApp Transport Security Settings
. - Add a row of Type
Dictionary
and of KeyException Domains
. - Add a row of Type
Dictionary
and of KeyThe domain
. - Add two rows of Type
Boolean
and of KeyNSExceptionAllowsInsecureHTTPLoads
&NSIncludesSubdomains
with Value toYES
.
Links
https://forums.developer.apple.com/message/5857#5857
iOS 9 HTTP Connection Error - StackOverflow
这篇关于NSURLSession "HTTP 加载失败 kCFStreamErrorDomainSSL, -9813 ;自签名证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!