N
Nelson R.
Hi,
i need to get some info from a website page that requires an
certificate.
Ive got the provided certificate installed in IE, and when accessing
the website page, it shows a window to select the client certificate
and then shows the page correctly.
Im trying to do this by code (vs2003 C# aspnet), using webrequest.
The certificate is in an pfx file and does not require password. I've
exported the file using IE to DER encoded binary X.509 (.cer), since
its the only format used by .net webrequest certificates (?)
My code:
X509Certificate certificate =
X509Certificate.CreateFromCertFile(Server.MapPath("file.cer"));
HttpWebRequest req =
(HttpWebRequest)WebRequest.Create("https://websiteurl");
req.Method="POST";
req.ClientCertificates.Add(certificate);
// ...
// here goes the request response read
// ...
I got this error:
System.Net.WebException: The underlying connection was closed: Could
not establish secure channel for SSL/TLS. --->
System.ComponentModel.Win32Exception: The message received was
unexpected or badly formatted at
System.Net.TlsStream.EndRead(IAsyncResult asyncResult) at
System.Net.Connection.ReadCallback(IAsyncResult asyncResult) --- End
of inner exception stack trace --- at
System.Net.HttpWebRequest.CheckFinalStatus() at
System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at
System.Net.HttpWebRequest.GetResponse()....
From the error i can see that the certificate is invalid, because if i
dont use the certificate i get the same error messagem.
So... anyone knows how or point me to the right path to do a request
from an https website, using an pfx file?
Best regards,
Nelson R.
i need to get some info from a website page that requires an
certificate.
Ive got the provided certificate installed in IE, and when accessing
the website page, it shows a window to select the client certificate
and then shows the page correctly.
Im trying to do this by code (vs2003 C# aspnet), using webrequest.
The certificate is in an pfx file and does not require password. I've
exported the file using IE to DER encoded binary X.509 (.cer), since
its the only format used by .net webrequest certificates (?)
My code:
X509Certificate certificate =
X509Certificate.CreateFromCertFile(Server.MapPath("file.cer"));
HttpWebRequest req =
(HttpWebRequest)WebRequest.Create("https://websiteurl");
req.Method="POST";
req.ClientCertificates.Add(certificate);
// ...
// here goes the request response read
// ...
I got this error:
System.Net.WebException: The underlying connection was closed: Could
not establish secure channel for SSL/TLS. --->
System.ComponentModel.Win32Exception: The message received was
unexpected or badly formatted at
System.Net.TlsStream.EndRead(IAsyncResult asyncResult) at
System.Net.Connection.ReadCallback(IAsyncResult asyncResult) --- End
of inner exception stack trace --- at
System.Net.HttpWebRequest.CheckFinalStatus() at
System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at
System.Net.HttpWebRequest.GetResponse()....
From the error i can see that the certificate is invalid, because if i
dont use the certificate i get the same error messagem.
So... anyone knows how or point me to the right path to do a request
from an https website, using an pfx file?
Best regards,
Nelson R.