尝试使用基本授权通过https连接到Web服务,但是我无法使其工作。我得到的错误消息:CFNetwork SSLHandshake失败(-9806)。感谢您的帮助。以下是相关代码:
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()
答案 0 :(得分:0)
此问题与基本授权无关,因为这是在成功进行SSL握手后完成的。根据您的https://localhost:8080
网址,我建议您至少遇到以下问题之一,但可能有几个:
localhost
)中的名称不匹配。我建议您使用浏览器检查网址,以了解有关该问题的更多信息。