Downloading a file from a website requesting a digital certificate

Discussion in 'ASP .Net' started by =?Utf-8?B?RWRkaWUgTGFzY3U=?=, Jul 10, 2007.

  1. Hello everybody,

    I am struggling with this issue for a few days now. I need to create an
    automatic process to daily download a file from a server that requires a
    digital certificate. The protocol used is HTTPS. This is what I did so far:

    // obtain a collection of certificates
    X509Store store = new X509Store("MY", StoreLocation.CurrentUser);
    store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
    collection = (X509Certificate2Collection)store.Certificates;
    fcollection =
    (X509Certificate2Collection)collection.Find(X509FindType.FindByTimeValid,
    DateTime.Now, false);

    // URL for my file to download
    string myFile2Get = "https://www.MySecureWebsite.com/MyFile.txt";

    // create the specialized Web Request object
    HttpWebRequest objHttpWebReq = WebRequest.Create(myFile2Get) as
    HttpWebRequest;

    // add the collection of the certificates
    objHttpWebReq.ClientCertificates = fcollection;

    // default method is GET

    // get the response to my request
    HttpWebResponse response = objHttpWebReq.GetResponse() as HttpWebResponse;

    // Get the stream associated with the response.
    Stream receiveStream = response.GetResponseStream();
    Encoding encode = System.Text.Encoding.GetEncoding("utf-8");

    // Pipes the stream to a higher level stream reader
    // with the required encoding format.
    StreamReader readStream = new StreamReader(receiveStream, encode);

    Console.WriteLine("\r\nResponse stream received.");

    Char[] read = new Char[256];

    // Reads 256 characters at a time.
    int count = readStream.Read(read, 0, 256);

    Console.WriteLine("HTML...\r\n");

    while (count > 0)
    {
    // Dumps the 256 characters on a string and displays the string to the
    console.
    String str = new String(read, 0, count);
    Console.Write(str);
    count = readStream.Read(read, 0, 256);
    }

    Console.WriteLine("");

    // Releases the resources of the response.
    response.Close();

    // Releases the resources of the Stream.
    readStream.Close();


    There is no error thrown, but instead of getting the content of the text
    file I am trying to read, all I get is message saying "Virtual user
    'NameOfMyCertificate' is logged in". What am I doing wrong? How do I get to
    read the file and not just some status message? Is this something that is
    done in two steps: connect to the secure site and then request the file? If
    so, what would be the sequence?

    Any help will be highly appreciated.

    All the best,
    Eddie
     
    =?Utf-8?B?RWRkaWUgTGFzY3U=?=, Jul 10, 2007
    #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. =?Utf-8?B?RWRkaWUgTGFzY3U=?=

    Downloading a file from a server that requires a digital certifica

    =?Utf-8?B?RWRkaWUgTGFzY3U=?=, Jul 9, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    273
    =?Utf-8?B?RWRkaWUgTGFzY3U=?=
    Jul 10, 2007
  2. jimgardener

    how to get a digital certificate

    jimgardener, Oct 23, 2008, in forum: Java
    Replies:
    11
    Views:
    6,052
    Roedy Green
    Oct 27, 2008
  3. suresh123kiran
    Replies:
    2
    Views:
    372
    suresh123kiran
    Aug 18, 2012
  4. Daniele Futtorovic
    Replies:
    0
    Views:
    298
    Daniele Futtorovic
    Aug 17, 2012
  5. suresh123kiran
    Replies:
    2
    Views:
    325
    suresh123kiran
    Aug 18, 2012
Loading...

Share This Page