posts - 11, comments - 8, 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();

Stream responseStream = httpResponse.GetResponseStream();
StreamReader sr = new StreamReader(responseStream);
// Do stuff with the Stream

responseStream.Close();

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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

Feedback

Gravatar

# re: C# HTTPS File Download

It doesn't work. You willl get error saying ServicePointManager doenot support scheme with HTTPS
5/26/2011 11:44 PM | some Developer
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: