无法与Web服务建立SSL连接C#

时间:2016-08-08 08:45:21

标签: c# web-services ssl certificate

我正在尝试连接到网络服务。我是SSL的新手。这是我的代码:

public void SendRequest(string httpsUrl, string postData, String[] certificates, String password)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(httpsUrl);

request.Method = "POST";

byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;


X509Certificate certificate = null;
foreach (String cert in certificates)
{
    certificate = new X509Certificate(cert, password);
    request.ClientCertificates.Add(certificate); //add cert
}

Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
}

request.GetRequestStream()抛出异常:“底层连接已关闭:无法为SSL / TLS安全通道建立信任关系”。

证书是由Web服务提供商(.cer文件)提供给我的,以及密码(key.dat),我想这可能是我的私钥。

为什么会抛出此错误的任何想法?难道我做错了什么?

0 个答案:

没有答案