具有基本身份验证的HttpWebRequest总是返回创建SSL/TLS通道失败



我正试图通过https和基本身份验证将我的本地程序连接到Wooccommerce RestAPI网站。我可以通过失眠连接到该网站,并且可以很好地处理这些细节。

然而,在代码中,缺少了一些东西。我已经在强制TLS1.2了,头信息中的键与失眠生成的键相匹配,我就是无法继续。。。我知道我显然错过了一些东西!

ServicePointManager.Expect100Continue = true;
ServicePointManager.DefaultConnectionLimit = 9999;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://mytestwebsite.com/wp-json/wc/v3/products?sku=CSB4X4");
string encoded = System.Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes("ck_..." + ":" + "cs_..."));
req.Headers.Add("Authorization", "Basic " + encoded);

req.Method = "GET";
req.Accept = "*/*";
req.ContentType = "application/json";
HttpWebResponse response = (HttpWebResponse)req.GetResponse();

当试图从请求中提取响应时,错误出现在最后一行"System.Net.WebException:"请求已中止:无法创建SSL/TLS安全通道。">

我试着记录system.net项目,但没有什么有趣的东西跳出来。

原来这是一个特定于机器的问题,而不是代码。

最新更新