Skip to content

Instantly share code, notes, and snippets.

@stinaq
Last active December 12, 2015 02:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stinaq/4698149 to your computer and use it in GitHub Desktop.
Save stinaq/4698149 to your computer and use it in GitHub Desktop.
private void button2_Click(object sender, EventArgs e)
{
ReadFromTheInternets internetReader = new ReadFromTheInternets("http://stinaq.me/license.txt", richTextBox1);
Thread myThread = new Thread(new ThreadStart(internetReader.ReadWebPage));
myThread.Start();
}
class ReadFromTheInternets
{
HttpWebRequest request;
RichTextBox textBox;
public ReadFromTheInternets(string url, RichTextBox textBox)
{
request = (HttpWebRequest) WebRequest.Create(url);
this.textBox = textBox;
}
public void ReadWebPage()
{
StringBuilder sb = new StringBuilder();
byte[] buf = new byte[8192];
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream resStream = response.GetResponseStream();
string tempString = null;
int count = 0;
do
{
count = resStream.Read(buf, 0, buf.Length);
if (count != 0)
{
tempString = Encoding.ASCII.GetString(buf, 0, count);
sb.Append(tempString);
}
}
while (count > 0);
MessageBox.Show(sb.ToString());
System.IO.File.WriteAllText(@"C:\Users\Stina\Desktop\test.txt", sb.ToString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment