1

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?

  • Just confirm, if you are accepting SSL certificate during HTTPS request. – Ankit Thakur Oct 30 '15 at 04:06
  • @AnkitThakur excuse me, but how? I try this solution http://stackoverflow.com/questions/30739149/how-do-i-accept-a-self-signed-ssl-certificate-using-ios-7s-nsurlsession , but it's not solve problem. – Илья Необутов Oct 30 '15 at 04:20
  • Just verify with this solution:http://stackoverflow.com/questions/5044477/determining-trust-with-nsurlconnection-and-nsurlprotectionspace – Ankit Thakur Oct 30 '15 at 06:55

0 Answers0