posts - 11, comments - 0, trackbacks - 0

My Links

News

Archives

C# HTTPS File Download

Don't Think too hard!!!
Sadly, I did not follow my own advice, thus spurring this post.
Simple Code to Download a file from an HTTPS Source.
Just make sure you trust the certificate being served up.

using System;
using System.IO;
using System.Net;

WebClient webClient = new WebClient();
webClient.Credentials = new NetworkCredential("username", "password", "domain");
webClient.DownloadFile("https://servername/path/documentToDownload.txt", "localPathToSaveFile");

If you want a Stream to read the data from:

HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(@"https://httpsServer/fileToDownload.txt");
httpRequest.Credentials = new NetworkCredential("username", "password", "domain");
HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse();

// Do stuff with the Stream

responseStream.Close();

Print | posted on Friday, September 04, 2009 10:02 PM |

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: