The following code fails:
let url = URL(string: "https://www.cardboardconnection.com/1987-topps-baseball-cards")!
var request = URLRequest(url: url)
request.setValue("text/html; charset=utf-8", forHTTPHeaderField: "Content-Type")
request.setValue("text/html; charset=utf-8", forHTTPHeaderField: "Accept")
let task = URLSession.shared.dataTask(with: request) {(data, response, error) in
guard let data = data else { return }
print(String(data: data, encoding: .utf8)!)
}
task.resume()
I can't figure out what specifically about this individual website is causing it to fail on the UTF8 conversion. How do I figure this out? And what is the proper conversion? Just looking to get the raw HTML from page.