ios - AFNetworking 3 问题
<p><p>在 <code>AFNetworking</code> 3 中我使用了无效的 SSL 证书 <strong>validatesCertificateChain = false</strong> ,但现在看来该字段已被删除,我无法向我的服务器发出请求。 </p>
<p><strong>这是请求类:</strong></p>
<pre><code>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
}
}
}
</code></pre>
<p><strong>我通过以下方式提出请求:</strong></p>
<pre><code>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)
})
</code></pre>
<p>根据 <a href="https://stackoverflow.com/questions/27808249/problems-with-ssl-pinning-and-afnetworking-2-5-0-nsurlerrordomain-error-1012" rel="noreferrer noopener nofollow">this post</a>我必须使用 <code>validatesCertificateChain</code> 属性。有人可以帮忙吗?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我通过将 <code>let securityPolicy = AFSecurityPolicy(pinningMode: AFSSLPinningMode.certificate)</code> 更改为 <code>let securityPolicy = AFSecurityPolicy(pinningMode: AFSSLPinningMode.none)</code> 解决了这个问题 </p></p>
<p style="font-size: 20px;">关于ios - AFNetworking 3 问题,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/40624568/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/40624568/
</a>
</p>
页:
[1]