在UIWebView上使用swift 2开机自检不起作用 [英] POST with swift 2 on UIWebView does not work

查看:91
本文介绍了在UIWebView上使用swift 2开机自检不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在swift 2之前,下面的代码可以正常工作.但是,在升级到Swift 2之后,下面的代码不再起作用.我已经通过Postman和RESTClient验证了我的Web服务是否有效.

Before swift 2, the code below used to work. However after upgrading to Swift 2, my code below no longer worked. I had verified with Postman and RESTClient that my web services worked.

let url = NSURL(string: "https://")
        let mutableURL = NSMutableURLRequest(URL:url!)
        mutableURL.HTTPMethod = "POST"
        let str = "user_id=90031963"
        mutableURL.HTTPBody = str.dataUsingEncoding(NSUTF8StringEncoding)
        leaderboardWebView.loadRequest(mutableURL)

任何评论和反馈将不胜感激.

Any comments and feedback will be very much appreciated.

欢呼

推荐答案

在安全的在线连接方面,Swift2非常严格.可能是由于您的服务器没有有效的ssh证书而导致连接被拒绝.为了进行测试,请尝试将以下字典添加到您的info.p中:

Swift2 is very strict when it comes to secure online connection. It could be the connection is rejected because your server doesn't have a valid ssh certificate. For test purpose try to add to your info.plist this Dictionary:

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

如果有效,则意味着您需要检查服务器安全性设置. 您可以在此处阅读有关此内容的更多信息: https://developer.apple.com/library/prerelease/ios/technotes/App-Transport-Security-Technote/

If it works, it means you need to check your server security setup. You can read more about it over here: https://developer.apple.com/library/prerelease/ios/technotes/App-Transport-Security-Technote/

请注意,除非您确实不需要安全连接,否则苹果不建议您使用此词典.

Note that Apple does not recommend to use this dictionary unless you are not really requiring a secure connection.

这篇关于在UIWebView上使用swift 2开机自检不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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