I try to execute GET request via HTTP by this code:
func httpGet(request: NSURL, callback: (String, String) -> Void) {
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithURL(request) {
(data,response,error) -> Void in
if (error != nil) {
callback("", error!.localizedDescription)
} else {
let result = NSString(data: data!, encoding: NSASCIIStringEncoding)
callback(result! as String, "")
}
}
task.resume()
}
func updateIssueList () {
httpGet(NSURL(string: "http://www.google.com")!) {
(data, error) -> Void in
print("error: \(error)")
print("data: \(data)")
}
}
It's executed correctly, and returns data without error. But when I change protocol to HTTPS (https://www.google.com"), request fails. When I tried to run application on device (iPhone 4s), I recieved
Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo=0x17579730 {NSErrorFailingURLStringKey=https://www.google.com, NSErrorFailingURLKey=https://www.google.com, NSLocalizedDescription=The network connection was lost., NSUnderlyingError=0x1758e470 "The network connection was lost."}
On simulator both variants work correctly. What I doing wrong?