"The remote certificate is invalid according to the validation procedure"

J

jens Jensen

Hello,

I'm trying to connect to a system via https. As an additional security
measure, the server requires me to attach an x509 certs to my "HTTP POST"
request.




I get the error described in the subject.

see code listing below:

bool result = false; ;

X509Certificate2 Certificate = null;



X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);


store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);

try

{



X509Certificate2Collection collection =
(X509Certificate2Collection)store.Certificates;

X509Certificate2Collection fcollection =
(X509Certificate2Collection)collection.Find(X509FindType.FindBySubjectName,
ConfigurationManager.AppSettings["SN"], false);



if (fcollection.Count == 0)

throw new Exception("Unable to find certificate!");

else

{

Certificate = fcollection[0];

// Certificate.

HttpWebRequest req =
(HttpWebRequest)HttpWebRequest.Create(ConfigurationManager.AppSettings["URI"]);

req.ClientCertificates.Add(Certificate);

req.Connection.

// if (ConfigurationManager.AppSettings["IRW_URI"].ToString()!="") req.Proxy
= new System.Net.WebProxy(ConfigurationManager.AppSettings["ProxyString"],
true);

req.ContentType = "application/x-www-form-urlencoded";

// req.Method = "POST";

// req.AuthenticationLevel = System.Net.Security.AuthenticationLevel.None;


byte[] bytes =
System.Text.Encoding.ASCII.GetBytes(Utility.ConvertMessagetoUTF8("data"));

req.ContentLength = bytes.Length;

System.Net.WebResponse resp = req.GetResponse();

......



......



.....



.....





......



The remote certificate is invalid according to the validation procedure



well googling haviong resolved the issue yet.



can someone help?



Thanks



JJ
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top