gpt4 book ai didi

iOS https/主机没有 SSL 证书

转载 作者:行者123 更新时间:2023-11-28 15:28:52 24 4
gpt4 key购买 nike

我遇到了问题,需要帮助。我通过 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()

我的错误:

The certificate for this server is invalid. You might be connecting to a server that is pretending to be “IP” which could put your confidential information at risk.

请帮帮我。

最佳答案

您需要允许Allow Arbitrary Loads。在您的 info.plist 文件中,添加以下条目

enter image description here

关于iOS https/主机没有 SSL 证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44934329/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com