I "wrote" this code and it works very well. It is to login to a site and retrieve the data so I can see what the Bitcoin price currently is. *But it does not update After i initially logged in and retrieved data the data there after stay the same(I have a timer to call the function again and I did put in keep alive)The idea is to send a login once and there after get updated data *Do I need to request all data or can I request only a selected amount for instance Thanks in advance. `namespace WindowsFormsApp7 { public partial class Form1 : Form { private string elementId = "BTC"; private Timer timer1; HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
public Form1()
{
InitializeComponent();
InitTimer();
}
public void InitTimer()
{ //initiaize and keep a timer
timer1 = new Timer();
timer1.Tick += new EventHandler(timer1_Tick);//run "timer1_Tick" function when timer is up
timer1.Interval = 60000; // in miliseconds
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (doc.Text != "")
{
getNumbers(doc);
}
}
private void btnGo_Click(object sender, EventArgs e)
{
//txtOutput.Text = "Working ...";
var Adress = new Uri(txtUrl.Text);
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(Adress);
request.KeepAlive = true;
//set the cookie container object
var cookieContainer = new CookieContainer();
request.CookieContainer = cookieContainer;
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36";
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
//set method POST and content type application/x-www-form-urlencoded
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
//insert your username and password
string data = string.Format("username={0}&password={1}", txtUserName.Text, txtPassword.Text);
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(data);
request.ContentLength = bytes.Length;
//post username & password
using (Stream dataStream = request.GetRequestStream())
{
dataStream.Write(bytes, 0, bytes.Length);
dataStream.Close();
}
getData(request);
}
private void getData(HttpWebRequest request)
{
using (WebResponse response = request.GetResponse())
{
doc.Load(response.GetResponseStream());
getNumbers(doc);
}
}
private void getNumbers(HtmlAgilityPack.HtmlDocument doc)
{
HtmlNode node = doc.DocumentNode;
var element = doc.GetElementbyId(elementId);
string amount = element.InnerText.Replace(" ", " ").Replace(";", "");
int rindex = amount.IndexOf("R");
txtRValue.Text = amount.Substring(rindex, (rindex + 12) - rindex);
debugOutput( amount.Substring(rindex, (rindex + 12) - rindex));
}
private void cboCurrency_SelectedIndexChanged(object sender, EventArgs e)
{
switch (cboCurrency.Text)
{
case "ETH":
elementId = "ETH";
break;
default:
elementId = "BTC";
break;
}
getNumbers(doc);
}
#region Debug
private void debugOutput(string strDebugText)
{
try
{
System.Diagnostics.Debug.Write(strDebugText + Environment.NewLine);
txtOutput.Text = txtOutput.Text + strDebugText + Environment.NewLine;
txtOutput.SelectionStart = txtOutput.TextLength;
txtOutput.ScrollToCaret();
}
catch (Exception ex)
{
System.Diagnostics.Debug.Write(ex.Message.ToString() + Environment.NewLine);
}
}
#endregion
}
} `