[tut]how to get website source using HttpWebRequest in c#

All tutorials created in C# to be posted in here.
3 posts Page 1 of 1
Contributors
User avatar
Shim
VIP - Donator
VIP - Donator
Posts: 882
Joined: Wed Dec 14, 2011 5:02 am

hello guys :)

i am up with a tutorial after a longtime so this is my first tutorial in c# and i am so happy to write this here

so lets start off

you need a button , textbox and a richtextbox

add this namespaces
Code: Select all

using System.Net;
using System.IO;


add this to button 1
Code: Select all

string url = textBox1.Text; //string textbox
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); //make request
HttpWebResponse response = (HttpWebResponse)request.GetResponse(); //new response 
StreamReader sr = New StreamReader(response.GetResponseStream()); //stream reader
richTextBox1.Text = sr.ReadToEnd(); //sr.readtoend

sr.Close();

now your done :P :P

thanks for reading
Find my programs on Softpedia
User avatar
Scottie1972
Codenstuff Elite
Codenstuff Elite
Posts: 953
Joined: Thu Jan 14, 2010 5:48 am

ok?
question?
what does this do?
and
how can it be used in or with my projects?
Image
User avatar
Shim
VIP - Donator
VIP - Donator
Posts: 882
Joined: Wed Dec 14, 2011 5:02 am

Scottie1972 wrote:
ok?
question?
what does this do?
and
how can it be used in or with my projects?
i am kinda new to c# and this will get the source of website using HttpWebRequest
Find my programs on Softpedia
3 posts Page 1 of 1
Return to “C-Sharp Tutorials”