gpt4 book ai didi

ios - Alamofire 失败并显示 SSL 错误代码 : -1200

转载 作者:行者123 更新时间:2023-11-30 11:38:22 25 4
gpt4 key购买 nike

我正在连接到自签名 URL,因此我已配置为禁用此 URL 的 SSL 证书评估。我正在使用 Alamofire 进行网络操作。

static let sessionManager: SessionManager = {
let configuration = URLSessionConfiguration.default
configuration.timeoutIntervalForRequest = NetworkConfiguration.sessionTimeoutInterval
configuration.httpAdditionalHeaders = [
"Accept": "application/json",
"Content-Type": "application/json"
]
let serverTrustPolicies: [String: ServerTrustPolicy] = [
"xyz.com:12345" : .disableEvaluation
]
let trustPolicyManager = ServerTrustPolicyManager(policies: serverTrustPolicies)
return Alamofire.SessionManager(configuration: configuration, serverTrustPolicyManager: trustPolicyManager)
}()

我还在我的 info.plist 文件中禁用了 ATS:

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

这是我连接 API 服务的方式:

        WebService.sessionManager.request(url, method: .get, parameters: params, encoding: resource.method.encodingFormat(), headers: headers)
.validate(statusCode: 200..<300)
.validate(contentType: ["application/json"])
.responseJSON { response in

let requestAPI = response.request?.url?.absoluteString
print("**********network Manager request: \(requestAPI ?? "request not found") ")

switch response.result {
case .success:
if let json = response.data {
print("############Network Manager response: \(String(data: json, encoding: String.Encoding.utf8) ?? "Response Data could not be printed")")
completion(json, nil)
} else {
}

case .failure(let error):
let errorFailureCode = (error as NSError).code
print("Network manager failure with reason: \(error.localizedDescription)")
completion(nil, error)
}

}

尽管如此,我还是收到错误:

NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9800) Task <68BD48CA-81E0-427C-B37F-50091A66EC7C>.<1> HTTP load failed (error code: -1200 [3:-9800]) Alamofire error - An SSL error has occurred and a secure connection to the server cannot be made.

最佳答案

尝试从主机字符串中删除端口。

let serverTrustPolicies: [String: ServerTrustPolicy] = [
"xyz.com" : .disableEvaluation
]

关于ios - Alamofire 失败并显示 SSL 错误代码 : -1200,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49487988/

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