【发布时间】: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
【问题讨论】:
-
在 IOS9 中运行良好
-
非常感谢@vaibav