在 AFNetworking
3 中我使用了无效的 SSL 证书 validatesCertificateChain = false ,但现在看来该字段已被删除,我无法向我的服务器发出请求。
这是请求类:
import UIKit
import AFNetworking
class ClientHTML: AFHTTPSessionManager {
private static var __once: () = { () -> Void in
let securityPolicy = AFSecurityPolicy(pinningMode: AFSSLPinningMode.certificate)
securityPolicy.validatesDomainName = false
securityPolicy.allowInvalidCertificates = true
sharedInstanceTemp.securityPolicy = securityPolicy
sharedInstanceTemp.requestSerializer = AFHTTPRequestSerializer()
sharedInstanceTemp.responseSerializer = AFHTTPResponseSerializer()
}()
fileprivate static let sharedInstanceTemp = ClientHTML(baseURL: URL(string: kServer_urlBilderlings))
static var sharedInstance:ClientHTML {
get {
_ = ClientHTML.__once
return sharedInstanceTemp
}
}
}
我通过以下方式提出请求:
ClientHTML.sharedInstance.post("https://acs-web-test.firstdata.lv", parameters: nil, progress: { (progress) in
print("progress = ", progress)
}, success: { (task, response) in
let data = response as! Data
let html = String(data: data, encoding: .utf8)
print("success responce = ", html)
}, failure: { (task, error) in
print("error = ", error)
})
根据 this post我必须使用 validatesCertificateChain
属性。有人可以帮忙吗?
我通过将 let securityPolicy = AFSecurityPolicy(pinningMode: AFSSLPinningMode.certificate)
更改为 let securityPolicy = AFSecurityPolicy(pinningMode: AFSSLPinningMode.none)
解决了这个问题
关于ios - AFNetworking 3 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40624568/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) | Powered by Discuz! X3.4 |