2016-08-23 8 views
0

今後、何かをテストしているので、サーバーのセキュリティを上書きしたいと考えています。グローバルAlamofireマネージャを作成し、サーバーの信頼ポリシーを設定しますが、動作しません。私はドメインを変更するが、それが同じであることを確認するために再度チェックする。Alamofireサーバーの信頼ポリシーが機能しません

class HTTPManager: Alamofire.Manager { 
    static let sharedManager: HTTPManager = { 

     let serverTrustPolicies: [String: ServerTrustPolicy] = [ 
      "qa.blah.me": .DisableEvaluation 
     ] 
     let serverTrustPolicyManger = ServerTrustPolicyManager(policies: serverTrustPolicies) 

     let configuration = Timberjack.defaultSessionConfiguration() 

     let manager = HTTPManager(configuration: configuration, serverTrustPolicyManager: serverTrustPolicyManger) 

     return manager 
    }() 
} 

これは私の使い方です。

HTTPManager.sharedManager.request(request).responseJSON(completionHandler: completionHandler) 

これは私が取得エラーメッセージです:私は間違って何をやっているとどのように私はそれを修正することができ

Error: The certificate for this server is invalid. You might be connecting to a server that is pretending to be “qa.blah.me” which could put your confidential information at risk. 
Suggestion: Would you like to connect to the server anyway? 

ありがとうございます!

PS:Alamofire 3.0

答えて

0

Alamofire.managerとしてマネージャをインスタンス化しようとする代わりにHTTPManager

0

あなたは最も可能性が高いので、ServerTrustPolicyはおそらく呼ばなっていませんATSに見舞われています。 Alamofire READMEのSecurityセクション全体を読んで、正しく設定されていることを確認することをお勧めします。

ServerTrustPolicyが呼び出されているかどうかを確認するには、serverTrustPolicyForHost()メソッドでブレークポイントを削除し、呼び出されるかどうかを確認します。

有効な証明書を削除しない理由もありません。無料の証明書はLet's Encryptに作成できます。

関連する問題