Why would my code below successfully return with data, with a statusCode of 200 but fail to convert the returned NSData to an NSString?
var session: NSURLSession
func init() {
let config = NSURLSessionConfiguration.defaultSessionConfiguration()
session = NSURLSession(configuration: config)
}
func getStatic(url:NSURL) {
let request = NSMutableURLRequest(URL: url)
let dataTask = session.dataTaskWithRequest(request) {(data, response, error) in
if error != nil {
// handle error
} else {
// data has a length of 2523 - the contents at the url
if let httpRes = response as? NSHTTPURLResponse {
// httpRes is 200
let html = NSString(data:data, encoding:NSUTF8StringEncoding)
// **** html is nil ****
}
}
}
dataTask.resume()
}