当前位置:   article > 正文

HttpWebRequest 请求HTTPS协议时报错:The requested security protocol is not supported. (不支持请求的安全协议)

the requested security protocol is not supported.
  1. public String Get(string url, byte[] data)
  2. {
  3. HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
  4. try
  5. {
  6. //服务器需安装.net4.5,否则报错:The requested security protocol is not supported. (不支持请求的安全协议)
  7. ServicePointManager.SecurityProtocol = ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
  8. //SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11
  9. //ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
  10. ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate;
  11. req.ProtocolVersion = HttpVersion.Version11;
  12. req.Method = "POST";
  13. req.KeepAlive = false;
  14. //req.Timeout = 1200000;
  15. req.ContentType = "application/x-www-form-urlencoded;charset=utf-8";
  16. //req.Headers.Add("ContentType", "application/x-www-form-urlencoded");
  17. req.Headers.Add("appKey", appKey);
  18. req.Headers.Add("appSecret", appSecret);
  19. req.ContentLength = data.Length;
  20. using (Stream reqStream = req.GetRequestStream())
  21. {
  22. reqStream.Write(data, 0, data.Length);
  23. }
  24. using (WebResponse response = req.GetResponse())
  25. {
  26. string text = "";
  27. using (Stream responseStm = response.GetResponseStream())
  28. {
  29. StreamReader redStm = new StreamReader(responseStm, Encoding.UTF8);
  30. text = redStm.ReadToEnd();
  31. }
  32. response.Close();
  33. //response = null;
  34. req.Abort();
  35. return text;
  36. }
  37. }
  38. catch (Exception ex)
  39. {
  40. if (ex.InnerException != null)
  41. {
  42. HttpContext.Current.Response.Write("内部错误信息:" + ex.InnerException.Message + "<br>");
  43. }
  44. req.Abort();
  45. throw ex;
  46. }
  47. return string.Empty;
  48. }

错误1:The requested security protocol is not supported. (不支持请求的安全协议)

原因:因为服务器上需安装.net4.5,(如果无效可以尝试重装IIS)

错误2:The remote name could not be resolved: 'nginx.platform.xxxxxx.cn'

原因:服务器无法解析这个域名,需要配置DNS解析

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/954295
推荐阅读
相关标签
  

闽ICP备14008679号