【问题标题】:Unable to make request using Alamofire due to- TIC SSL Trust Error由于 TIC SSL 信任错误,无法使用 Alamofire 发出请求
【发布时间】:2018-09-27 07:08:47
【问题描述】:

我已设置 - 允许任意加载为 YES

我正在使用以下代码来触发请求:

let apiAddress = somehttpsAddress
let configuration = URLSessionConfiguration.default
configuration.timeoutIntervalForRequest = 30 // seconds
configuration.timeoutIntervalForResource = 30 //seconds
AFManager = Alamofire.SessionManager(configuration: configuration)
AFManager.request(apiAddress , method: .post, parameters: body, encoding: JSONEncoding.default, headers: header).responseJSON { response in
            // utility
}

但是我得到的只是这些错误:

TIC SSL Trust Error [1:0x60c000161c80]: 3:0
NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)

我不明白这里缺少什么以及我应该如何更正它。请帮我纠正这个问题。

【问题讨论】:

标签: ios swift xcode alamofire


【解决方案1】:

如果您连接到一些公共网络或校园网络,他们可能已经安装了一些限制软件,例如 Cyber​​oam。您提出请求的地址可能受到限制。您可以请求访问该特定网站的权限。

【讨论】:

  • 其实是一个不安全的链接。未屏蔽。
【解决方案2】:

这里的问题是 Alamofire 认为它不是有效的 ssl 证书。尝试将其用作您的经理:

    private static var Manager : Alamofire.SessionManager = {
    // Create the server trust policies
    let serverTrustPolicies: [String: ServerTrustPolicy] = [
        "your domain goes here": .disableEvaluation
    ]
    // Create custom manager
    let configuration = URLSessionConfiguration.default
    configuration.httpAdditionalHeaders = Alamofire.SessionManager.defaultHTTPHeaders
    let man = Alamofire.SessionManager(
        configuration: URLSessionConfiguration.default,
        serverTrustPolicyManager: ServerTrustPolicyManager(policies: serverTrustPolicies)
    )
    return man
}()

【讨论】:

  • 没有错误,事实上它现在连链接都没有。状态码是纯 nil
  • 奇怪,试试这个stackoverflow.com/a/40784254/5135104 请按照描述更改 plist 和代码
  • 为我工作!即使没有.pList 条目。
猜你喜欢
  • 1970-01-01
  • 2023-03-20
  • 1970-01-01
  • 1970-01-01
  • 2017-10-29
  • 2018-07-30
  • 1970-01-01
  • 1970-01-01
  • 2021-11-16
相关资源
最近更新 更多