【问题标题】:Getting Error While making rest call in swift 3 for iOS 10在 iOS 10 的 swift 3 中进行休息时出错
【发布时间】:2016-10-28 11:24:41
【问题描述】:
let url string = "https://myURL"

func task(_ urlstring: String,json: AnyObject, ComplitionHandler: @escaping taskCompletionHandler  )
{
    do
    {
        let jsonData = try JSONSerialization.data(withJSONObject: json, options: .prettyPrinted)
        let url = URL(string: urlstring)
        var request = URLRequest(url: url!)
        request.httpMethod = "POST"
        request.httpBody = jsonData
        request.addValue("application/json", forHTTPHeaderField: "Content-Type")

        let task = URLSession.shared.dataTask(with: request, completionHandler: {(data,response,error) in

                if(error != nil)
                {
                    print(error)
                    ComplitionHandler(nil, nil )
                    return
                }
                ComplitionHandler(data!, response!)
        })            
        task.resume()
    }
    catch
    {
        print("error")
    }
}

我在.plist 中添加了一些更改 (App Transport Security ,Allow Arbitrary Loads=YES,Allow Arbitrary Loads in Web Content=YES).

但仍然出现以下错误:

NSLocalizedDescription=发生 SSL 错误,无法与服务器建立安全连接。, NSErrorFailingURLKey=https://myurl, NSErrorFailingURLStringKey=https://myurl, NSErrorClientCertificateStateKey=0

【问题讨论】:

标签: ios swift xcode rest


【解决方案1】:

好吧,受信任的根证书列表已在 iOS 10 上更新,因此判断您应该确保您的 SSL 证书不是 iOS 10 阻止的根证书的一部分。

Updated List

如果您有 WoSign CA 免费 SSL 证书 G2,Apple 会阻止它,因为他们声称它有多个控制失败。更多信息here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-11
    • 2017-03-19
    • 2017-04-13
    • 1970-01-01
    • 1970-01-01
    • 2018-02-26
    • 1970-01-01
    • 2017-02-14
    相关资源
    最近更新 更多