0
試圖通過基本授權通過https連接到web服務,但我無法讓它工作。我收到的錯誤消息:CFNetwork SSLHandshake失敗(-9806)。感謝你的幫助。這裏是相關的代碼:基本授權 - SSL握手失敗
var post : NSString = "username=\(username)&password=\(password)"
let postData = post.dataUsingEncoding(NSUTF8StringEncoding)
let base64EncodedCredential = postData!.base64EncodedStringWithOptions(nil)
NSLog("PostData: %@",post);
var url : NSURL = NSURL(string: "https://localhost:8080/webservice")!
var postLength : NSString = String(base64EncodedCredential.lengthOfBytesUsingEncoding(NSUTF8StringEncoding))
var request:NSMutableURLRequest = NSMutableURLRequest(URL: url)
request.HTTPMethod = "POST"
request.HTTPBody = postData
request.setValue("Basic \(base64EncodedCredential)", forHTTPHeaderField: "Authorization")
request.setValue(postLength, forHTTPHeaderField: "Content-Length")
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.setValue("application/json", forHTTPHeaderField: "Accept")
let queue:NSOperationQueue = NSOperationQueue()
let urlConnection = NSURLConnection(request: request, delegate: self, startImmediately: true)
urlConnection!.start()
http://stackoverflow.com/questions/25914248/ios-8-has-broken-ssl-connection-in-my-app-cfnetwork-sslhandshake-failed-9806 – 2015-04-01 18:00:05