我遇到了问题,需要帮助。我通过HTTPS向服务器发送请求,但服务器没有SSL证书。我如何绕过iOS中的SSL证书?
我的代码:
let loginString = String(format: "Login:Pass")
let loginData = loginString.data(using: String.Encoding.utf8)!
let base64LoginString = loginData.base64EncodedString()
let headers = [
"content-type": "application/xml",
"authorization": "Basic \(base64LoginString)"
]
let postData = NSData(data: "BODY".data(using: String.Encoding.utf8)!)
let request = NSMutableURLRequest(url: URL(string: "IP")!, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data
var session = URLSession.shared
session = URLSession(configuration: URLSessionConfiguration.default, delegate: self as? URLSessionDelegate, delegateQueue: nil)
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
if (error != nil) {
print(error.debugDescription)
} else {
let responseData = String(data: data!, encoding: String.Encoding.utf8)!
print(responseData)
}
})
dataTask.resume()
我的错误:
此服务器的证书无效。您可能连接到假装为“IP”的服务器,这可能会使您的机密信息面临风险。
请帮帮我。