Last active
December 12, 2015 02:18
-
-
Save stinaq/4698149 to your computer and use it in GitHub Desktop.
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
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