2016-11-16 77 views
0

AFNetworking 3對於無效SSL證書我用validatesCertificateChain = false,但現在看起來這個字段已被刪除,我無法向我的服務器發出請求。AFNetworking 3問題

這裏是要求等級:

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財產。任何人都可以幫忙嗎? http://cocoadocs.org/docsets/AFNetworking/3.0 -

+0

我還看到,allowInvalidCertificates財產AFSecurityPolicy存在AFNetworking 3.0.0,請參閱本文檔解決它。 0-beta.1/Classes/AFSecurityPolicy.html – iamyogish

+0

我使用此屬性,但我需要另一個validatesCertificateChain,我需要將其設置爲false。請看看這個問題的最佳答案http://stackoverflow.com/questions/27808249/problems-with-ssl-pinning-and-afnetworking-2-5-0-nsurlerrordomain-error-1012。他們說這個屬性,但它是飛網2 –

回答

1

我改變let securityPolicy = AFSecurityPolicy(pinningMode: AFSSLPinningMode.certificate)let securityPolicy = AFSecurityPolicy(pinningMode: AFSSLPinningMode.none)

+0

感謝您發佈您的答案,這將有助於稍後的人。 – iamyogish