Connect to web site using SSL & Client Certificates

Discussion in 'ASP .Net' started by Krishna, May 17, 2004.

  1. Krishna

    Krishna Guest

    Well, I got it working when running against my test server (IIS5 W2K
    svr, I will attach a sample of the code at the bottom of this
    message), but now I'm connecting to our client (Apache) I'm getting
    the following error:

    An unhandled exception of type 'System.Net.WebException' occurred in
    system.dll

    Additional information: The underlying connection was closed: Unable
    to connect to the remote server.


    This exception is thrown when the GetRequestStream() method is
    called and I am using a client cert that was issued to us from their
    internal CA (they are using OpenSSL).

    Any help'd be much appreciated!

    Regards,kg.


    public void Connect()
    {
    // Doesn't work
    X509Certificate cert =
    X509Certificate.CreateFromCertFile("c:\\Certificates\\client_cert.cer");
    WebRequest request = GetWebRequest(new
    Uri("https://client_web/methodserver.php"));

    // Works
    //X509Certificate cert =
    X509Certificate.CreateFromCertFile("c:\\Certificates\\verisign_cert.cer");
    //WebRequest request = GetWebRequest(new
    Uri("https://server.com/testpage.aspx"));


    request.ContentType = "text/xml";
    request.Method = "POST";

    HttpWebRequest httpRequest = (HttpWebRequest)request;
    httpRequest.UserAgent = "Exel Test";
    httpRequest.Headers = new WebHeaderCollection();
    httpRequest.ClientCertificates.Add(cert);

    request = (WebRequest)httpRequest;

    // This is where it breaks...
    Stream reqStream = request.GetRequestStream();
    reqStream.Close();

    WebResponse resp = GetWebResponse(request);
    Stream respStream = resp.GetResponseStream();

    TextReader tr = new StreamReader(respStream, new UTF8Encoding(), true,
    4096);

    string certInfo = tr.ReadToEnd();

    System.Diagnostics.Debug.WriteLine(certInfo);
    }
    Krishna, May 17, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Krishna
    Replies:
    1
    Views:
    3,584
    Krishna
    May 19, 2004
  2. RR
    Replies:
    1
    Views:
    512
    Scott Allen
    Mar 4, 2005
  3. News123
    Replies:
    9
    Views:
    3,054
    vilas
    Feb 15, 2012
  4. Matthew
    Replies:
    0
    Views:
    371
    Matthew
    Nov 2, 2004
  5. n33470

    Are SSL certificates and x.509 certificates the same?

    n33470, Dec 14, 2005, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    172
    n33470
    Dec 14, 2005
Loading...

Share This Page