Swift/https:NSURLSession/NSURLConnection HTTP加载失败 [英] Swift/https: NSURLSession/NSURLConnection HTTP load failed

查看:66
本文介绍了Swift/https:NSURLSession/NSURLConnection HTTP加载失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不幸的是,今天早上我的XCode更新到了版本7,而我正在使用http开发的iOS应用现在需要https.因此,在完成许多教程之后,我配置了MAMP服务器,以便使用https/ssl创建虚拟证书.现在,在我的iOS应用中,URL如下所示:

Unfortunately this morning my XCode updated to version 7 and the iOS app I was developing with http now wants https. So, following many tutorials, I configured my MAMP server in order to use https/ssl creating a dummy certificate. Now in my iOS app URLs are like the following:

static var webServerLoginURL = "https://localhost:443/excogitoweb/mobile/loginM.php"
static var webServerGetUserTasks = "https://localhost:443/excogitoweb/mobile/handleTasks.php"
static var webServerGetUsers = "https://localhost:443/excogitoweb/mobile/handleUsers.php"
static var webServerGetProjects = "https://localhost:443/excogitoweb/mobile/handleProjects.php"

,如果我尝试在浏览器中访问它们,它们会正常工作.我曾经使用NSURLSession.sharedSession().dataTaskWithRequest()访问数据库和php文件,这现在引起标题错误.例如,这是引发错误的行:

and they work fine if I try to access them in my browser. I was used to access the database and php files with NSURLSession.sharedSession().dataTaskWithRequest() which now raises the error in title. For example, here's the line where error is raised:

if let responseJSON: [[String: String]] = (try? NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions())) as? [[String: String]] {
...
}

这是完整的错误消息:

2015-09-21 16:41:48.354 ExcogitoWeb[75200:476213] CFNetwork SSLHandshake failed (-9824)
2015-09-21 16:41:48.355 ExcogitoWeb[75200:476213] NSURLSession/NSURLConnection   HTTP load failed (kCFStreamErrorDomainSSL, -9824)
fatal error: unexpectedly found nil while unwrapping an Optional value

我想知道如何解决此问题.我在这里阅读了一些有用的答案,但是还有很多我还是不明白的事情,如果有人能帮助/解释我,我将非常感激.

I would like to know how to fix this. I've read some useful answers here but there are many things I still don't understand and if anyone would help/explain me I'd be very grateful.

推荐答案

将此添加到应用程序的 Info.plist

Add this to your app's Info.plist

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

这篇关于Swift/https:NSURLSession/NSURLConnection HTTP加载失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆