I am trying to execute the following script:
import Foundation
class TestURLSession{
var session: NSURLSession!
func run(){
session = NSURLSession.sharedSession()
let url = NSURL(string: "http://www.veenex.de/tmp/json")
let request = NSMutableURLRequest(URL: url!)
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
request.HTTPMethod = "GET"
let getDataTask = session.dataTaskWithRequest(request, completionHandler: {(data, response, error) in
// HTTP Response contains an error
if let httpResponse = response as? NSHTTPURLResponse {
if httpResponse.statusCode != 200 {
print("response was not 200: \(response)")
return
}
}
// Error submitting Request
if error != nil {
print("error submitting request: \(error)")
return
}
// print data
if data != nil{
do {
let json = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers) as! NSArray
for entry in json {
print(entry)
}
} catch {
print("Error printing data")
}
}
});
getDataTask.resume()
}
}
let testURLSession = TestURLSession()
testURLSession.run()
But I receive the error message: "Error running code: unknown error code 132.". Executing the code in the Xcode Playground it works.