小编plg*_*lso的帖子

Swift 和 Alamofire SSL 固定和处理挑战

当我尝试从内部 Web 服务器获取 json 时,我需要应对挑战。我从上一个问题中遵循了这一点。这是我的代码

let defaultManager: Alamofire.SessionManager = {
            let serverTrustPolicies: [String: ServerTrustPolicy] = [
                "myhttpsinternaldomain.org": .disableEvaluation
            ]

            let configuration = URLSessionConfiguration.default
            configuration.httpAdditionalHeaders = Alamofire.SessionManager.defaultHTTPHeaders

            return Alamofire.SessionManager(
                configuration: configuration,
                serverTrustPolicyManager: ServerTrustPolicyManager(policies: serverTrustPolicies)
            )
        }()

        let url = URL(string: urlString)
        let username = "user"
        let password = "password"
        let header = ["user": username, "password": password]

        defaultManager.request(url!, method: .get, headers: header).responseJSON { response in
            switch response.result {
            case .success(let value):
                let json = JSON(value)
                print("JSON: \(json)")
            case .failure(let error): …
Run Code Online (Sandbox Code Playgroud)

json challenge-response swift alamofire

0
推荐指数
1
解决办法
3472
查看次数

标签 统计

alamofire ×1

challenge-response ×1

json ×1

swift ×1