gpt4 book ai didi

ios - 如何信任端点 iOS swift

转载 作者:可可西里 更新时间:2023-11-01 00:55:34 26 4
gpt4 key购买 nike

我正在调用具有自签名 ssl 证书的端点我已尝试将其添加到我的 info.plist

<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>

但我仍然无法访问我一直收到的端点

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

最佳答案

您需要创建一个 session 管理器并告诉它禁用对该服务器中的 ssl 的评估。

像这样

static var manager: Alamofire.SessionManager = {
let serverTrustPolicies: [String: ServerTrustPolicy] = [
"https://example.com": .disableEvaluation
]

let configuration = URLSessionConfiguration.default
configuration.httpAdditionalHeaders = Alamofire.SessionManager.defaultHTTPHeaders
let manager = Alamofire.SessionManager(
configuration: URLSessionConfiguration.default,
serverTrustPolicyManager: ServerTrustPolicyManager(policies: serverTrustPolicies)
)

return manager
}()

然后,而不是像这样在 Alamofire 中调用请求

Alamofire.request("https://example.com", method: .get…

你在你的经理中调用它

manager.request("https://example.com"…

关于ios - 如何信任端点 iOS swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49496736/

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