2

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

1 回答 1

3

您需要创建一个会话管理器并告诉它禁用对该服务器中 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"…
于 2018-03-26T17:33:56.880 回答