小编Rog*_*r G的帖子

错误:C#底层连接已关闭:无法为SSL/TLS安全通道建立信任关系

我正在尝试通过SSL发出请求.证书已安装在计算机上,可通过浏览器运行.

我正在使用此请求:

System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] data = encoding.GetBytes(request.Content.OuterXml.ToString());
string password = "XXXX";
X509Certificate2 cert = new X509Certificate2("c:\\zzzz.p12", password);
string key = cert.GetPublicKeyString();
string certData = Encoding.ASCII.GetString(cert.Export(X509ContentType.Cert));

Uri uri = new Uri(request.Url);
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(uri);
myRequest.Credentials = new NetworkCredential(request.User, request.Password.ToString());
myRequest.Method = "PUT";
myRequest.ContentType = request.ContentType;
myRequest.ContentLength = data.Length;
myRequest.ClientCertificates.Add(cert);

Stream newStream = myRequest.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();

System.IO.StreamReader st = new StreamReader(((HttpWebResponse)myRequest.GetResponse()).GetResponseStream());
Run Code Online (Sandbox Code Playgroud)

使用此代码我收到此错误:

底层连接已关闭:无法为SSL/TLS安全通道建立信任关系.---> System.Security.Authentication.AuthenticationException:根据验证程序,远程证书无效.

问题是什么?

c# ssl certificate put httpwebrequest

26
推荐指数
1
解决办法
7万
查看次数

标签 统计

c# ×1

certificate ×1

httpwebrequest ×1

put ×1

ssl ×1