swift - basic Authorization - SSL Handshake failed -
trying connect webservice on https basic authorization, cant work. error message get: cfnetwork sslhandshake failed (-9806). appreciate help. here relevant code:
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()
the problem has nothing basic authorization, since done after successful ssl handshake. based on url of https://localhost:8080
suggest have @ least 1 of following problems, maybe several:
- no https spoken, plain http. port 8080 unusual https, used http.
- name in certificate not match name in url (
localhost
). - certificate not signed authority trusted client.
i recommend check url browser find more issue.
Comments
Post a Comment