zoukankan      html  css  js  c++  java
  • https

    代码
       public string DoHTTPSComm(string url,string para, string method,string certUrl,string certpwd)
            {
               
                
    string s = "";
                
    try
                {
                    HttpWebRequest request 
    = (HttpWebRequest)HttpWebRequest.Create(url);
                    request.Method 
    = "POST";
                    request.ContentType 
    = "application/x-www-form-urlencoded";

                    
    //创建证书实例
                    X509Certificate m_X509Certificate = new X509Certificate();

                    m_X509Certificate.Import(certUrl, certpwd, X509KeyStorageFlags.DefaultKeySet);
                 

                    
    //添加到请求的证书集合中
                    request.ClientCertificates.Add(m_X509Certificate);
                    
    //传输实际内容
                    s = para;

                    request.ContentLength 
    = System.Text.Encoding.GetEncoding("GBK").GetBytes(s).LongLength;

                    System.IO.Stream sm 
    = request.GetRequestStream();

                    sm.Write(System.Text.Encoding.GetEncoding(
    "GBK").GetBytes(s), 0, System.Text.Encoding.GetEncoding("GBK").GetBytes(s).Length);
                    sm.Close();

                    System.IO.StreamReader sr 
    = new System.IO.StreamReader(request.GetResponse().GetResponseStream(), System.Text.Encoding.GetEncoding("GBK"));

                    s 
    = "";

                    s 
    = sr.ReadToEnd();
     
                }
                
    catch (Exception ex)
                {
                    s_logger.WriteErrLog(
    "IPS3.CAT.Common.Socket""DoHTTPSComm""连接异常", ex);

                    
    return "";
                }

                
    return s;
            }
     
     

      public static string DoHTTPSComm(string url, string para, string method, string certUrl, string certpwd)
            {
                string s = "";
                // 线程锁
                mu.WaitOne();

                try
                {
                    if (s_pay == null)
                    {
                        s_pay = new IPS3.CAT.Common.com.ecitic.bank.test.pay.PaymentServicesService();

                        X509Certificate m_X509Certificate = new X509Certificate();

                        m_X509Certificate.Import(certUrl, certpwd, X509KeyStorageFlags.DefaultKeySet);

                        //添加到请求的证书集合中
                        s_pay.ClientCertificates.Add(m_X509Certificate);

                        s_pay.Url = url;
                    }

                    // session使用
                    s_pay.CookieContainer = cookieContainer;

                    Type type = s_pay.GetType();

                    MethodInfo m = type.GetMethod(method);

                    // 调用方法接口
                    s = (string)m.Invoke(s_pay, new object[] { para });

                }
                catch (Exception ex)
                {
                    s_logger.WriteErrLog("IPS3.CAT.Common.Socket", "DoHTTPSComm", "连接异常", ex);

                    return "";
                }
                finally
                {
                    mu.ReleaseMutex();
                }

                return s;
            }

  • 相关阅读:
    转(一致性哈希算法(consistent hashing))
    【CMD】findstr命令
    【Android】 Sqlite3 not found
    【Android】Sqlite3命令详解
    数据结构-哈夫曼树
    数据结构-线索化二叉树
    【原创】解决国内Android SDK无法更新问题更新
    数据结构-插入排序之希尔排序
    数据结构-插入排序之直接插入排序
    数据结构-二叉树的遍历
  • 原文地址:https://www.cnblogs.com/duwamish/p/1644614.html
Copyright © 2011-2022 走看看