1

I'm trying to see if I can connect to https://www.google.com with:

do {
    let s = try String(contentsOf: URL(string: "https://www.google.com/")!, encoding: .utf8)
    print(s)
} catch {
    print(error)
}

The error I receive is:

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}

Viewing the page info on https://www.google.com states that it is using UTF-8:

enter image description here

Why is it always throwing an error?

Daniel Storm
  • 18,301
  • 9
  • 84
  • 152

0 Answers0