赞
踩
我是测试环境的正常的,上生产之后出现的问题
主要就是这部分:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | (SecurityProtocolType)3072;
public static string HttpPost(string url, string data, string auth) { HttpWebResponse wr = null; string _resContent = ""; try { ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | (SecurityProtocolType)3072;// | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls13 | SecurityProtocolType.SystemDefault; var request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.ContentType = "application/json;charset=UTF-8"; request.Headers.Add("Authorization", auth); byte[] byteData = Encoding.UTF8.GetBytes(data); int length = byteData.Length; request.ContentLength = length; Stream writer = request.GetRequestStream(); writer.Write(byteData, 0, length); writer.Close(); wr = (HttpWebResponse)request.GetResponse(); _resContent = new StreamReader(wr.GetResponseStream(), Encoding.GetEncoding("utf-8")).ReadToEnd(); wr.Close(); } catch (Exception exp) { LogHelper.Info("httpPost接口::" + exp.Message); } return _resContent.ToString(); }
完美解决!
原文链接:.net framework 4.0未能创建 SSL/TLS 安全通道
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。