• 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;
            }

  • 相关阅读:
    jenkins master-slave配置
    ansible-playbook 变量(vars)
    ansible-playbook && Roles && include
    ansible 循环与条件判断when
    python 微信爬虫实例
    JavaScript: 零基础轻松学闭包
    【干货】用大白话聊聊JavaSE — ArrayList 深入剖析和Java基础知识详解(二)
    【干货】用大白话聊聊JavaSE — ArrayList 深入剖析和Java基础知识详解(一)
    【大结局】《从案例中学习JavaScript》之酷炫音乐播放器(四)
    Java 实现批量重命名,亲测可用(精简版)
  • 原文地址:https://www.cnblogs.com/duwamish/p/1644614.html
Copyright © 2020-2023  润新知