End Google Ads 201810 - BS.net 01 --> Hi,

In order to create a dashboard application, I need to read an HTML site's source code.
This contains the values (integers) which I want to process.

I don't have access to the SQL-database, so this is the only way I can achieve my goal, and deliver the application.

The site uses a Username & Password as security, and I am able to access the login page.
However, when passing the credentials, I'm not able to read the source code (it seems like the credentials aren't valid).
However, when using the same credentials directly in Internet Explorer, I'm able to access the webpage.

This is the code I have so far.
Any of you experts see what I'm doing wrong?
PS: I've changed the site-url, username & password, since it's a confidential site of my company.



public static string GetHtmlPageSource(string url, string username, string password)
{
System.IO.Stream st = null;
System.IO.StreamReader sr = null;
try
{
// make a Web request
System.Net.WebRequest req = System.Net.WebRequest.Create(url);
// if the username/password are specified, use these credentials
if (username != null && password != null)
req.Credentials = new System.Net.NetworkCredential(username, password);
// get the response and read from the result stream
System.Net.WebResponse resp = req.GetResponse();
st = resp.GetResponseStream();
sr = new System.IO.StreamReader(st);
// read all the text in it
return sr.ReadToEnd();
}
catch (Exception ex)
{
return string.Empty;
}
finally
{
// always close readers and streams
sr.Close();
st.Close();
}
}

private void Data*******_Tick(object sender, EventArgs e)
{
// Set the ******* Interval to 15000 ms
this.Data*******.Interval = 15000;

// Declare the Variables, needed for this Application
string FL, SL, UnFL, UnSL, ValueFL, ValueSL, ValueUnFL, ValueUnSL;

//// ******* the TopDesk Web Browser Object
this.TopDesk.*******();

//Read WebPage
string page;

page = GetHtmlPageSource("https://site", "user", "pass");



// Set Values to "Nothing"
ValueFL = null;
ValueSL = null;
ValueUnFL = null;
ValueUnSL = null;
FL = null;
SL = null;
UnFL = null;
UnSL = null;

// Read & Analyse the Webpage shown in the Web Browser Object, and use certain values displayed here
try
{
FL = page.Substring(5510, 7);
SL = page.Substring(6361, 7);
UnFL = page.Substring(5721, 7);
UnSL = page.Substring(6572, 7);
}
catch
{
DialogResult buttonResult = MessageBox.Show("Website not accessible. Please check the network connection, and check your login credentials on the TopDesk-website.", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
if (buttonResult == DialogResult.OK)
{
this.Close();
}
}

// Loop through the obtained data, and check if the characters are Numeric
for (int X = 0; X < 8; X++)
{
int valueA = int.Parse(FL.Substring(X, 1));
ValueFL = ValueFL + FL.Substring(X, 1);

int valueB = int.Parse(SL.Substring(X, 1));
ValueSL = ValueSL + SL.Substring(X, 1);

int valueC = int.Parse(UnSL.Substring(X, 1));
ValueUnSL = ValueUnSL + UnSL.Substring(X, 1);

int valueD = int.Parse(UnFL.Substring(X, 1));
ValueUnFL = ValueUnFL + UnFL.Substring(X, 1);


try
{

}
catch
{
Debug.WriteLine("ValueFL: " + FL.Substring(X, 1) + " is not a valid Integer.");
}

try
{
}
catch
{
Debug.WriteLine("ValueSL: " + SL.Substring(X, 1) + " is not a valid Integer.");
}

try
{
}
catch
{
Debug.WriteLine("ValueUnSL: " + UnSL.Substring(X, 1) + " is not a valid Integer.");
}

try
{
}
catch
{
Debug.WriteLine("ValueUnFL: " + UnFL.Substring(X, 1) + " is not a valid Integer.");
}
}

// Calculate the Total number of Calls, FL + SL
int TotalCalls;
TotalCalls = Convert.ToInt32(ValueFL) + Convert.ToInt32(ValueSL);

// Fill Values in the DashBoard
this.aGaugeSL.Value = Convert.ToInt32(ValueSL);
this.aGaugeFL.Value = Convert.ToInt32(ValueFL);
this.txtBoxFLOpen.Text = ValueFL;
this.txtBoxSLOpen.Text = ValueSL;
this.lblOpenCallsFLNbr.Text = ValueFL;
this.lblOpenCallsSLNbr.Text = ValueSL;
this.lblUnassignedCallsFLNbr.Text = ValueUnFL;
this.lblUnassignedCallsSLNbr.Text = ValueUnSL;
this.lblTotalCallsFL_SL.Text = "Total Number of Open Calls (FL + SL): " + Convert.ToString(TotalCalls);

// ******* all Objects
aGaugeFL.*******();
aGaugeSL.*******();
txtBoxFLOpen.*******();
txtBoxSLOpen.*******();
lblTotalCallsFL_SL.*******();
lblUnassignedCallsFLNbr.*******();
lblUnassignedCallsSLNbr.*******();
lblOpenCallsFLNbr.*******();
lblOpenCallsSLNbr.*******();
pictureBoxStatusFL.*******();
pictureBoxStatusSL.*******();
}

}