Reputation: 937
I am creating a simple web browser in C#. I have been instructed not to use the webbrowser class provided, so I have to code everything. I am struggling to load the page from my url. Here's my code:
private void toolStripButton5_Click(object sender, EventArgs e)
{
url = "http://" + toolStripTextBox1.Text;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream pageStream = response.GetResponseStream();
StreamReader reader = new StreamReader(pageStream);
}
StripButton5 corresponds to my navigate button in my form. The problem i'm having is when I type the address like www.google.com. the page just hangs and doesn't load. Any suggestions appreciated.
Upvotes: 0
Views: 123
Reputation: 937
Had to encode and then read the HTML then get the browser to display it in html.
private void toolStripButton5_Click(object sender, EventArgs e)
{
url = "http://" + toolStripTextBox1.Text;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream pageStream = response.GetResponseStream();
StreamReader reader = new StreamReader(pageStream,Encoding.Default);
string s = reader.ReadToEnd();
webBrowser1.DocumentText = s;
}
Upvotes: 2