I've a problem. Safari can load the page http://ip-api.com/json
, but a URLSession task cannot.
Here's the code inside viewDidLoad
let url = URL(string: "http://ip-api.com/json")!
let request = URLRequest(url: url)
let task = URLSession.shared.dataTask(with: request, completionHandler: {(data, response, error) -> Void in
print("this is the server response: \(response)")
if error != nil {
print("some error: \(error)")
} else {
if let urlContent = data {
print(urlContent)
}
}
})
task.resume()
The console log reports the following error content:
... some error: Optional(Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection." UserInfo={NSUnderlyingError=0x60800005bc00 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 "(null)"}, NSErrorFailingURLStringKey=http://ip-api.com/json, NSErrorFailingURLKey=http://ip-api.com/json, NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.})