问题
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.
Cheers
回答1:
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>
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.
来源:https://stackoverflow.com/questions/32834393/post-with-swift-2-on-uiwebview-does-not-work