objective c - iOS Basic Auth completion error first time -


i have implemented piece of code basic auth , doesn't work on first time:

func dorequestwithbasicauth(completion : (success : bool, html: string?, error : nserror?) -> void) {     if let user = self.user {         let loginstring = nsstring(format: "%@:%@", user.login!, user.pwd!)         let logindata: nsdata = loginstring.datausingencoding(nsutf8stringencoding)!         let base64loginstring = logindata.base64encodedstringwithoptions(nil)         let url = nsurl(string: user.service!.geturl())         let request = nsmutableurlrequest(url: url!)         request.httpmethod = "post"         request.setvalue("basic \(base64loginstring)", forhttpheaderfield: "authorization")         nsurlconnection.sendasynchronousrequest(request, queue: nsoperationqueue.mainqueue()) {(response, data, error) in             if error == nil {                 let htmlstring = nsstring(data: data, encoding: nsutf8stringencoding)                 completion(success: true, html: htmlstring as? string, error: nil)             } else {                 completion(success: false, html: nil, error: error)             }         }     } else {         completion(success: false, html: nil, error: nserror())     } } 

this method attached button, on first tap error:

basic auth error: error domain=nsurlerrordomain code=-1012 "the operation couldn’t completed. (nsurlerrordomain error -1012.)" userinfo=0x7bad5770 {nserrorfailingurlkey=https:///auth/logon.do, nserrorfailingurlstringkey=https:///auth/logon.do, nsunderlyingerror=0x7b9c47f0 "the operation couldn’t completed. (kcferrordomaincfnetwork error -1012.)"}

on second tap, call works fine... can't understand why.. print user login, psw , url: same on twice calls..

any idea?


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -