using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Net;
using System.IO;
/*
* HtmlDocument is class helping to obtain HTML source code from URL that we provide
* Input : URL we want to perform navigation testing
* Output : Scenario obtianed based on URL proximity
* Methods :
* Form1() : Initialization of data
* btn_Html_Click() : TO start the navigation testing operation
* getHTML() : Function to obtain source of URL specified
* Form1_Load() : Event Handler for form1 "load" event
* */
namespace HtmlDocument
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btn_Html_Click(object sender, EventArgs e)
{
/*
* Attributes:
* url - URL of web page we want to test
* pagesource - string variable which stores source code of webpage
* myWeb
*
*/
string url=string.Empty;
url=txt_url.Text;
if (url ==string.Empty)
{
MessageBox.Show("Enter url");
}
else
{
try
{
string pagesource = getHtml(url);
richTextBox1.Text = pagesource;
System.Diagnostics.Process.Start(url);
}
catch (Exception ex)
{
MessageBox.Show("Error In retreiving code");
}
}
}
string getHtml(string url)
{
HttpWebRequest myWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
myWebRequest.Method = "GET";
// make request for web page
HttpWebResponse myWebResponse = (HttpWebResponse)myWebRequest.GetResponse();
StreamReader myWebSource = new StreamReader(myWebResponse.GetResponseStream());
string myPageSource = string.Empty;
myPageSource= myWebSource.ReadToEnd();
myWebResponse.Close();
return myPageSource;
}
private void Form1_Load(object sender, EventArgs e)
{
this.Text = "HTML SOURCE APPLICATION";
}
}
}
No comments:
Post a Comment