i'm writing a snippet of code to get the source code of an html page from a website but the variable sourceCode remains null and it does not get the html code
this is my code
class HtmlClass
{
public static string getSourceCode(string url)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(resp.GetResponseStream());
string sourceCode = sr.ReadToEnd();
sr.Close();
resp.Close();
return sourceCode;
}
}
and this is where i use it:
private void button3_Click(object sender, EventArgs e)
{
string url = textBox1.Text;
string sourceCode = HtmlClass.getSourceCode(url);
}
can you please tell me what might be wrong???