ios - how to bypass the local connection in swift -


i want test local web service call check data server. don't know make connection local host in swift here provide sample code practiced

override func viewdidload() {  let request = nsmutableurlrequest(url: nsurl(string: "http://localhost:9000/api/v1/entitylist")!)  var theconnection: nsurlconnection = nsurlconnection(request: request, delegate: self, startimmediately: true)!  }   func connection(connection: nsurlconnection, canauthenticateagainstprotectionspace protectionspace: nsurlprotectionspace) -> bool {     return true }    func connection(connection: nsurlconnection, canauthenticateagainstprotectionspace protectionspace: nsurlprotectionspace) -> bool {     return true }  func connection(connection: nsurlconnection, didreceiveauthenticationchallenge challenge: nsurlauthenticationchallenge) {      if (challenge.protectionspace.host == "http://localhost:9000/api/v1/entitylist") {          challenge.sender!.usecredential(nsurlauthenticationchallenge.autocontentaccessingproxy() as! nsurlcredential, forauthenticationchallenge: challenge)      }   } 

my log statement is

  error=optional(error domain=nsurlerrordomain code=-1004 "could not    connect server." userinfo={nsunderlyingerror=0x7fc9705525a0 {error domain=kcferrordomaincfnetwork code=-1004 "(null)" userinfo=   {_kcfstreamerrorcodekey=61, _kcfstreamerrordomainkey=1}},    nserrorfailingurlstringkey=http://localhost:9000/api/v1/entitylist,   nserrorfailingurlkey=http://localhost:9000/api/v1/entitylist,    _kcfstreamerrordomainkey=1, _kcfstreamerrorcodekey=61,    nslocalizeddescription=could not connect server.}) 

the reason error api request not able find address have given.

the address have given

http://localhost:9000/api/v1/entitylist 

you have change

http://domainname.com/api/v1/entitylist 

where domainname.com should name or dns of server in local network. can pc or else pc has capability of acting web server.

another thing have take care have bypass nstranportsecurity token ios 9 doesnt support unsecured requests. in short request should server supports https

you can bypass adding following code plist

    <key>nsapptransportsecurity</key> <dict>    <key>nsallowsarbitraryloads</key>       <true/> </dict> 

if need more information on can visit following link

link

link 2

hope helps you....


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -