I am trying to get and print the HTML from a URL. Here's how I do it (with Swift 2):
let testUrl = NSURL(string: "https://www.google.com")
var html = NSString()
do {
html = try NSString(contentsOfURL: testUrl!, encoding: NSUTF8StringEncoding)
} catch{print(error)}
print(html)
And the following error is printed in console:
Error Domain=NSCocoaErrorDomain Code=261 "The file couldn’t be opened using text encoding Unicode (UTF-8)." UserInfo={NSURL=https://www.google.com, NSStringEncoding=4}
Any idea?