【问题标题】:How to trust an endpoint iOS swift如何快速信任端点 iOS
【发布时间】:2018-09-04 21:49:21
【问题描述】:

我正在调用具有自签名 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.

【问题讨论】:

标签: ios swift alamofire nsapptransportsecurity


【解决方案1】:

您需要创建一个会话管理器并告诉它禁用对该服务器中 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"…

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多