www.RickLaFleur.com

 

Simple method to download Web resource

Had to look this up - again - so writing a quick note for future reference.

public static string Download(string url)
{
    HttpWebRequest httpWebRequest =
      (HttpWebRequest)WebRequest.Create(url);

    HttpWebResponse httpWebResponse =
     (HttpWebResponse)httpWebRequest.GetResponse();

    Stream stream = httpWebResponse.GetResponseStream();

    StreamReader streamReader =
      new StreamReader(stream, Encoding.ASCII);

    return streamReader.ReadToEnd();
}

Labels:


Comments: Post a Comment



Links to this post:

Create a Link



<< Home

Archives

January 2007  |   March 2007  |   May 2007  |   February 2008  |   April 2008  |   July 2008  |   September 2008  |   October 2008  |   December 2008  |   January 2009  |   April 2009  |   May 2009  |   June 2009  |   December 2009  |   January 2010  |  

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]