OGeek|极客世界-中国程序员成长平台

标题: ios - AFNetworking 3 问题 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 14:25
标题: ios - AFNetworking 3 问题

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 属性。有人可以帮忙吗?



Best Answer-推荐答案


我通过将 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