zoukankan      html  css  js  c++  java
  • C# https客户端获取证书的工具方法

    1. 导入证书到个人计算机中



    2. 获取证书

    [csharp] view plain copy
     
     print?
    1. private static X509Certificate2 GetSentosaCertificate()  
    2.         {  
    3.             X509Store userCaStore = new X509Store(StoreName.My, StoreLocation.LocalMachine);  
    4.             try  
    5.             {  
    6.                 userCaStore.Open(OpenFlags.ReadOnly);  
    7.                 X509Certificate2Collection certificatesInStore = userCaStore.Certificates;  
    8.                 X509Certificate2Collection findResult = certificatesInStore.Find(X509FindType.FindBySubjectName, "*.sentosa.com.sg", true);  
    9.                 X509Certificate2 clientCertificate = null;  
    10.                 if (findResult.Count == 1)  
    11.                 {  
    12.                     clientCertificate = findResult[0];  
    13.                 }  
    14.                 else  
    15.                 {  
    16.                     throw new Exception("Unable to locate the correct client certificate.");  
    17.                 }  
    18.                 return clientCertificate;  
    19.             }  
    20.             catch  
    21.             {  
    22.                 throw;  
    23.             }  
    24.             finally  
    25.             {  
    26.                 userCaStore.Close();  
    27.             }  
    28.         }  


    3. 将证书附加在http请求中即可

    http://www.woaipu.com/shops/zuzhuan/61406
    http://www.znds.com/tv-967956-1-1.html
    http://www.znds.com/tv-967958-1-1.html

  • 相关阅读:
    nyoj_518_取球游戏_201404161738
    nyoj_528_找球号(三)_201404152050
    nyoj_68_三点顺序_201404152013
    nyoj_123_士兵杀敌(四)_201404131143
    树状数组
    nyoj_116_士兵杀敌(二)_201404131107
    hdu_1024_糖果大战_201404021640
    hdu_1205_吃糖果_201404021440
    nyoj_278_排队_201403282135
    nyoj_127_星际之门(一)_201403282033
  • 原文地址:https://www.cnblogs.com/sy646et/p/7198111.html
Copyright © 2011-2022 走看看