Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: HttpWebRequest and X509Certificates...anyone?


Message #1 by "Paul Tillotson" <paultillotson@q...> on Tue, 16 Jul 2002 01:37:04 -0600
Has anyone had luck accessing a secured SSL site using HttpWebRequest and
the X509Certificate class.  I keep getting the error "Could not establish
trust relationship with remote server.I have successfully exported a .pfx
file to a DES 509 certificate .cer file.
I then read in the certificate file with the code below and TRY to post data
to a HTTPS server.
Here is my code.
Thanks much Paul

////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////

X509Certificate x509
=509Certificate.CreateFromCertFile(@"c:\\MyDES509File.cer");
StreamWriter myWriter = null;
System.Net.HttpWebRequest objRequest;
objRequest 
(HttpWebRequest)System.Net.HttpWebRequest.Create(https://somesecuredServer/t
est.aspx);
objRequest.ClientCertificates.Add(x509);
objRequest.Method = "POST";
objRequest.ContentLength = strPost.Length;
objRequest.ContentType = "application/x-www-form-urlencoded";
try
{
  myWriter = new StreamWriter(objRequest.GetRequestStream());
  myWriter.Write("Test data to SSL port...");
}
catch (Exception err)
{
 string someerror=err.Message.ToString();
 ResultsBox.Text = "Error="+ someerror;
 return ;
}
myWriter.Flush();
myWriter.Close();



  Return to Index