禁用HTTPS GET证书检查
我的班级:
func getUsers() {
guard let url = URL(string: "https://localhost:5001/Zona/User") else {return print("ERROR")}
let urlRequest = URLRequest(url: url)
let dataTask = URLSession.shared.dataTask(with: urlRequest) { (data, response, error) in
if let error = error {
print("Request error: ", error)
return
}
guard let response = response as? HTTPURLResponse else { return }
if response.statusCode == 200 {
guard let data = data else { return }
DispatchQueue.main.async {
do {
let decodedUsers = try JSONDecoder().decode([User].self, from: data)
self.users = decodedUsers
} catch let error {
print("Error decoding: ", error)
}
}
}
}
dataTask.resume()
}
连接到本地服务器时,出现错误,即无法检查SLL
请求错误:错误域= nsurlorrordomain code = -1202“该服务器的证书无效。您可能正在连接到假装是“ Localhost”的服务器,该服务器可能会使您的机密信息处于风险中。”
My Class:
func getUsers() {
guard let url = URL(string: "https://localhost:5001/Zona/User") else {return print("ERROR")}
let urlRequest = URLRequest(url: url)
let dataTask = URLSession.shared.dataTask(with: urlRequest) { (data, response, error) in
if let error = error {
print("Request error: ", error)
return
}
guard let response = response as? HTTPURLResponse else { return }
if response.statusCode == 200 {
guard let data = data else { return }
DispatchQueue.main.async {
do {
let decodedUsers = try JSONDecoder().decode([User].self, from: data)
self.users = decodedUsers
} catch let error {
print("Error decoding: ", error)
}
}
}
}
dataTask.resume()
}
When connecting to a local server, it gives an error that it is impossible to check sll
Request error: Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “localhost” which could put your confidential information at risk."
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将此条目添加到info.plist
,并在URL中使用HTTP的HTTP Insteasd
add this entry to info.plist
and use the HTTP insteasd of HTTPS in URL