我正在尝试连接到网络服务 . 我是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()
抛出异常:"The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel" .
证书由Web服务提供商(.cer文件)和密码(key.dat)提供给我,我想这可能是我的私钥 .
任何想法为什么会抛出这个错误?难道我做错了什么?