i just want to test my local web service call to check my data from server. i don't know to make connection to local host in swift here i provide my sample code which i 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 to the 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 to the server.})