lundi 26 octobre 2015

NSURLSession in Swift 2 gives App Transport Security issues

I cannot figure out how to solve this issue. I want to connect to a remote database file (in this case sqlite), currently testing with the main site.

let url = NSURL(string: "http://ift.tt/1GDYSus")
let request = NSURLRequest(URL: url!)
let config = NSURLSessionConfiguration.defaultSessionConfiguration()
let session = NSURLSession(configuration: config)

let task : NSURLSessionDataTask = session.dataTaskWithRequest(request, completionHandler: {(data, response, error) in

    if error != nil {
        print("error: \(error!.localizedDescription): \(error!.userInfo)")
    }
    else if data != nil {
        if let str = NSString(data: data!, encoding: NSUTF8StringEncoding) {
            print("Received data:\n\(str)")
        }
        else {
            print("unable to convert data to text")
        }
    }

})

task.resume()

Working in XCode 7.1 with Swift 2. The code gives:

App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.

but the problem is that this server is not configured for HTTPS.

How should I connect to the database? (if possible I could convert to MySQL, but SQLite is preferable).

Aucun commentaire:

Enregistrer un commentaire