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