Created
March 19, 2012 12:01
-
-
Save CharlTruter/2109322 to your computer and use it in GitHub Desktop.
Loading a site's content in C# using backend code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string GetSiteContent(string url) | |
{ | |
// Create the web request for the url passed to the method | |
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url); | |
// For the sake of this example, we'll be using the GET method. | |
// For other options, please see http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.method.aspx | |
myRequest.Method = "GET"; | |
// Get the response and store it in a WebResponse object | |
using (WebResponse myResponse = myRequest.GetResponse()) | |
{ | |
// Read the result into a string | |
using (StreamReader sr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8)) | |
{ | |
string result = sr.ReadToEnd(); | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment