我正在使用Web.DownloadString()从雅虎股票下载数据;该网站将有多个用户,所以我需要让客户端发送下载请求而不是服务器,以避免被阻止从服务器IP地址发送太多请求。我无法找到在客户端运行它的方法,我正在寻求帮助,使其从客户端而不是服务器运行。
下面是一个格式不正确的功能,我打算清理我正在使用的功能
我计划只使用获取数据运行客户端所需的部分和剩下的运行服务器我还没有清理我的代码。
Public void DownloadData()
{
string csvData = null;
string month1 = Convert.ToString(DropDownList1.SelectedIndex);
string month2 = Convert.ToString(DropDownList2.SelectedIndex);
string Temp = "http://ichart.finance.yahoo.com/table.csv?s=" + SymbolName.Text + "&d=" + month2 + "&e=" + TextBox3.Text + "&f=" + TextBox4.Text + "&g=d&a=" + month1 + "&b=" + TextBox1.Text + "&c=" + TextBox2.Text + "&ignore=.csv";
string FileRead;
List<string> Remove1 = new List<string>();
string path = System.AppDomain.CurrentDomain.BaseDirectory;
using (WebClient web = new WebClient())
{
try
{
csvData = web.DownloadString(Temp);
}
catch
{
}
}
if (csvData != null && csvData != "")
{
File.WriteAllText(path + "\\MyTest.txt", csvData);
}
System.IO.StreamReader file = new System.IO.StreamReader(path + "\\MyTest.txt");
while ((FileRead = file.ReadLine()) != null) //reads from file
{
Remove1.Add(FileRead);
}
file.Close();
csvData = csvData.Replace("Date,Open,High,Low,Close,Volume,Adj Close", "");
List<stock> prices = YahooFinance.Parse(csvData);
double Lowest = 0;
foreach (stock price in prices) // finds lowest value to addjust priceing
{
if (Lowest == 0)
{
Lowest = Convert.ToDouble(price.low);
}
if (Lowest > Convert.ToDouble(price.low))
{
Lowest = Convert.ToDouble(price.low);
}
}
// new double[] { Convert.ToDouble(price.low), Convert.ToDouble(price.high), Convert.ToDouble(price.Open), Convert.ToDouble(price.close) }
Chart1.ChartAreas[0].AxisX.Interval = 2;
Chart2.ChartAreas[0].AxisX.Interval = 2;
Chart1.ChartAreas[0].AxisX.Maximum = prices.Count + 20;
Chart1.ChartAreas[0].AxisY.Minimum = Lowest - 3;
foreach (stock price in prices)
{
Chart1.Series[0].Points.AddXY(price.date, Convert.ToDouble(price.low), Convert.ToDouble(price.high), Convert.ToDouble(price.Open), Convert.ToDouble(price.close));
Chart2.Series[0].Points.AddXY(price.date, Convert.ToDouble(price.Volume));
}
}
`