110,566
社区成员
发帖
与我相关
我的任务
分享
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
//网上查到的所有资料,都说加上下面这一句就可以,但是我不仅加了,还把SecurityProtocolType的枚举一个个试了个遍,都不行。
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(“https://api.mch.weixin.qq.com/secapi/pay/refund”);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded;charset=utf8";
req.ContentLength = postBytes.Length;
string CertPath = HttpContext.Current.Request.PhysicalApplicationPath + "\\wx\\cert\\apiclient_cert.p12";
X509Certificate2 cert = new X509Certificate2(CertPath, WxPayAccount);
req.ClientCertificates.Add(cert);
//就这下面这句GetRequestStream时出错:出错信息:请求被中止: 未能创建 SSL/TLS 安全通道。
Stream reqStream = req.GetRequestStream();
reqStream.Write(postBytes, 0, postBytes.Length);
reqStream.Close();
WebResponse webRep = req.GetResponse();
StreamReader sr = new StreamReader(webRep.GetResponseStream(), System.Text.Encoding.UTF8);
RMsg = sr.ReadToEnd();