473,320 Members | 2,035 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Downloading a file from a website requesting a digital certificate

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(X509Fi ndType.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
Jul 10 '07 #1
0 1255

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Guangxi Wu | last post by:
Hi all, Happy New Year. I am using SignedXML and an X509 certificate to digitally sign a SOAP message body and put the signature in the SOAP header for a B2B business application. Can you...
5
by: kathyk | last post by:
Hi All, We are moving to Access 2003 in a month or so, so i started testing my data base files in v2003. When The mdb open I get 3 warning messagase about blocking unsafe expressions. Security...
2
by: Martin Høst Normark | last post by:
Hi everyone Has anyone got the least experience in integrating the Digital Signature with an ASP.NET Web Application? Here in Denmark, as I supose in many other countries, they're promoting...
6
by: Matt Frame | last post by:
I have a client that has asked us to get a digital signature certificate and start digitally signing all files we pass between each other. I have heard of the subject and know about the certs but...
0
by: Bryan Slatner | last post by:
I'm having some difficulty finding the information I need. Maybe someone can point me in the right direction. I need to call methods on a web service defined by one of our vendors. They require,...
3
by: Paul Phillips | last post by:
I have been struggling with this for a couple of weeks. I have a digital certificate installed in my certificate collection store on my local computer. The site I am trying to post to also has...
0
by: Paul Phillips | last post by:
I have been struggling with this for a couple of weeks. I have a digital certificate installed in my certificate collection store on my local computer. The site I am trying to post to also has...
1
by: =?Utf-8?B?RWRkaWUgTGFzY3U=?= | last post by:
Not sure this is the right place to ask my question, please bear with me. After reading the question, if you think there should be a different place let me know. I need to automate a daily...
5
by: troy_lee | last post by:
We have an application developed by one developer. He compiled the database into an application and digitally signed the application. He doesn't know if he used selfcert of makecert to make the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.