.net 低版本请求https 接口失败,,,升级.net版本后解决,,同时忽略ssl验证
public string HttpPost(string url, string body) { Encoding encoding = Encoding.UTF8; string jsonText = string.Empty; string dataText1 = string.Empty; if (string.IsNullOrEmpty(url.Trim())) { return ""; } //接收证书进行身份验证 ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult); //ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.Accept = "text/plain, */*; q=0.01"; request.ContentType = "application/json;charset=utf-8"; byte[] buffer = encoding.GetBytes(body); request.ContentLength = buffer.Length; request.GetRequestStream().Write(buffer, 0, buffer.Length); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) { jsonText = reader.ReadToEnd(); } return jsonText; } public bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) { //直接确认,否则打不开 return true; }
标签:web,return,string,ssl,c#,Encoding,request,buffer From: https://www.cnblogs.com/sishahu/p/18329799