C# HttpWebRequest在我的System.Net引用中不可见

C# HttpWebRequest在我的System.Net引用中不可见,c#,C#,我有一个WindowsApplication项目,其中引用文件夹缺少一个文件。我已经将其与另一个项目进行了比较,在那里我确实找到了该文件,应该可以在这里找到: 参考->系统->系统.Net->HttpWebRequest 我怎样才能将这个文件添加到我的项目中,为什么它不能自动加载,我是否做错了什么 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin

我有一个WindowsApplication项目,其中引用文件夹缺少一个文件。我已经将其与另一个项目进行了比较,在那里我确实找到了该文件,应该可以在这里找到: 参考->系统->系统.Net->HttpWebRequest

我怎样才能将这个文件添加到我的项目中,为什么它不能自动加载,我是否做错了什么

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GetStockData
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            string ticker = this.tbTicker.Text;
            DateTime startDate = this.dtpStart.Value;
            DateTime endDate = this.dtpEnd.Value;

            int startMonth = startDate.Month - 1;
            int endMonth = endDate.Month - 1;
            string theURL = @"http://ichart.finance.yahoo.com/table.csv?s=" 
                + ticker + @"&a=" + startMonth.ToString() + @"&b=" + startDate.Day.ToString() 
                + @"&c=" + startDate.Year.ToString() + @"&d=" + endMonth.ToString() + @"&e=" + endDate.Day.ToString() 
                + @"&f=" + endDate.Year.ToString() + @"&g=d&ignore=.csv";

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(theURL);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            Stream resStream = response.GetResponseStream();
            StringBuilder sb = new StringBuilder();
            byte[] buf = new byte[8192];
            string tempString = null;
            int count = 0;

            do {
                count = resStream.Read(buf, 0, buf.Length);
                if (count != 0) {
                    tempString = Encoding.ASCII.GetString(buf, 0, count);
                    sb.Append(tempString);
                    }
            }
            while (count > 0);
            string data = sb.ToString();
            String[] data2 = data.Split('\n');
            int iteration = 0;
            dates = new DateTime[data2.Length - 2];
            open = new double[data2.Length - 2];
            high = new double[data2.Length - 2];
            low = new double[data2.Length - 2];
            close = new double[data2.Length - 2];
            volume = new double[data2.Length - 2];
            adjClose = new double[data2.Length - 2];
            foreach (string strLine in data2)
            {
                String[] entries = strLine.Split(',');
                if ((iteration != 0) && (entries[0] != ""))
                {
                    dates[iteration - 1] = System.Convert.ToDateTime(entries[0]);
                    open[iteration - 1] = System.Convert.ToDouble(entries[1]);
                    high[iteration - 1] = System.Convert.ToDouble(entries[2]);
                    low[iteration - 1] = System.Convert.ToDouble(entries[3]);
                    close[iteration - 1] = System.Convert.ToDouble(entries[4]);
                    volume[iteration - 1] = System.Convert.ToDouble(entries[5]);
                    adjClose[iteration - 1] = System.Convert.ToDouble(entries[6]);
                }
                iteration = iteration + 1;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }
    }
}
问候 埃斯彭

我做错什么了吗

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GetStockData
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            string ticker = this.tbTicker.Text;
            DateTime startDate = this.dtpStart.Value;
            DateTime endDate = this.dtpEnd.Value;

            int startMonth = startDate.Month - 1;
            int endMonth = endDate.Month - 1;
            string theURL = @"http://ichart.finance.yahoo.com/table.csv?s=" 
                + ticker + @"&a=" + startMonth.ToString() + @"&b=" + startDate.Day.ToString() 
                + @"&c=" + startDate.Year.ToString() + @"&d=" + endMonth.ToString() + @"&e=" + endDate.Day.ToString() 
                + @"&f=" + endDate.Year.ToString() + @"&g=d&ignore=.csv";

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(theURL);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            Stream resStream = response.GetResponseStream();
            StringBuilder sb = new StringBuilder();
            byte[] buf = new byte[8192];
            string tempString = null;
            int count = 0;

            do {
                count = resStream.Read(buf, 0, buf.Length);
                if (count != 0) {
                    tempString = Encoding.ASCII.GetString(buf, 0, count);
                    sb.Append(tempString);
                    }
            }
            while (count > 0);
            string data = sb.ToString();
            String[] data2 = data.Split('\n');
            int iteration = 0;
            dates = new DateTime[data2.Length - 2];
            open = new double[data2.Length - 2];
            high = new double[data2.Length - 2];
            low = new double[data2.Length - 2];
            close = new double[data2.Length - 2];
            volume = new double[data2.Length - 2];
            adjClose = new double[data2.Length - 2];
            foreach (string strLine in data2)
            {
                String[] entries = strLine.Split(',');
                if ((iteration != 0) && (entries[0] != ""))
                {
                    dates[iteration - 1] = System.Convert.ToDateTime(entries[0]);
                    open[iteration - 1] = System.Convert.ToDouble(entries[1]);
                    high[iteration - 1] = System.Convert.ToDouble(entries[2]);
                    low[iteration - 1] = System.Convert.ToDouble(entries[3]);
                    close[iteration - 1] = System.Convert.ToDouble(entries[4]);
                    volume[iteration - 1] = System.Convert.ToDouble(entries[5]);
                    adjClose[iteration - 1] = System.Convert.ToDouble(entries[6]);
                }
                iteration = iteration + 1;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }
    }
}
您忘记添加:

using System.Net;
以便将定义类的命名空间引入范围

namespace GetStockData
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            string ticker = this.tbTicker.Text;
            DateTime startDate = this.dtpStart.Value;
            DateTime endDate = this.dtpEnd.Value;

            int startMonth = startDate.Month - 1;
            int endMonth = endDate.Month - 1;
            string theURL = @"http://ichart.finance.yahoo.com/table.csv?s=" 
            + ticker + @"&a=" + startMonth.ToString() + @"&b=" + startDate.Day.ToString() 
            + @"&c=" + startDate.Year.ToString() + @"&d=" + endMonth.ToString() + @"&e=" + endDate.Day.ToString() 
            + @"&f=" + endDate.Year.ToString() + @"&g=d&ignore=.csv";

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(theURL);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            Stream resStream = response.GetResponseStream();
            StringBuilder sb = new StringBuilder();
            byte[] buf = new byte[8192];
            string tempString = null;
            int count = 0;

            do {
                count = resStream.Read(buf, 0, buf.Length);
                if (count != 0) {
                    tempString = Encoding.ASCII.GetString(buf, 0, count);
                    sb.Append(tempString);
                }
            }
            while (count > 0);
            string data = sb.ToString();
            String[] data2 = data.Split('\n');
            int iteration = 0;
            dates = new DateTime[data2.Length - 2];
            open = new double[data2.Length - 2];
            high = new double[data2.Length - 2];
            low = new double[data2.Length - 2];
            close = new double[data2.Length - 2];
            volume = new double[data2.Length - 2];
            adjClose = new double[data2.Length - 2];
            foreach (string strLine in data2)
            {
                String[] entries = strLine.Split(',');
我做错什么了吗

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GetStockData
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            string ticker = this.tbTicker.Text;
            DateTime startDate = this.dtpStart.Value;
            DateTime endDate = this.dtpEnd.Value;

            int startMonth = startDate.Month - 1;
            int endMonth = endDate.Month - 1;
            string theURL = @"http://ichart.finance.yahoo.com/table.csv?s=" 
                + ticker + @"&a=" + startMonth.ToString() + @"&b=" + startDate.Day.ToString() 
                + @"&c=" + startDate.Year.ToString() + @"&d=" + endMonth.ToString() + @"&e=" + endDate.Day.ToString() 
                + @"&f=" + endDate.Year.ToString() + @"&g=d&ignore=.csv";

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(theURL);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            Stream resStream = response.GetResponseStream();
            StringBuilder sb = new StringBuilder();
            byte[] buf = new byte[8192];
            string tempString = null;
            int count = 0;

            do {
                count = resStream.Read(buf, 0, buf.Length);
                if (count != 0) {
                    tempString = Encoding.ASCII.GetString(buf, 0, count);
                    sb.Append(tempString);
                    }
            }
            while (count > 0);
            string data = sb.ToString();
            String[] data2 = data.Split('\n');
            int iteration = 0;
            dates = new DateTime[data2.Length - 2];
            open = new double[data2.Length - 2];
            high = new double[data2.Length - 2];
            low = new double[data2.Length - 2];
            close = new double[data2.Length - 2];
            volume = new double[data2.Length - 2];
            adjClose = new double[data2.Length - 2];
            foreach (string strLine in data2)
            {
                String[] entries = strLine.Split(',');
                if ((iteration != 0) && (entries[0] != ""))
                {
                    dates[iteration - 1] = System.Convert.ToDateTime(entries[0]);
                    open[iteration - 1] = System.Convert.ToDouble(entries[1]);
                    high[iteration - 1] = System.Convert.ToDouble(entries[2]);
                    low[iteration - 1] = System.Convert.ToDouble(entries[3]);
                    close[iteration - 1] = System.Convert.ToDouble(entries[4]);
                    volume[iteration - 1] = System.Convert.ToDouble(entries[5]);
                    adjClose[iteration - 1] = System.Convert.ToDouble(entries[6]);
                }
                iteration = iteration + 1;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }
    }
}
您忘记添加:

using System.Net;

以便将定义类的命名空间引入作用域。

谢谢Darin!它不是用我抄袭的代码写的,而且我太缺乏经验,也无法捕捉到丢失的语句。我注意到Stream和.GetResponseStream日期、open、high等都是黑色的,换句话说,它们似乎不能正常工作。有什么明显的东西我忘记添加了吗?
使用System.IO添加此项谢谢Darin!它不是用我抄袭的代码写的,而且我太缺乏经验,也无法捕捉到丢失的语句。我注意到Stream和.GetResponseStream日期、open、high等都是黑色的,换句话说,它们似乎不能正常工作。有什么明显的东西我忘记添加了吗?
使用System.IO添加此
namespace GetStockData
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            string ticker = this.tbTicker.Text;
            DateTime startDate = this.dtpStart.Value;
            DateTime endDate = this.dtpEnd.Value;

            int startMonth = startDate.Month - 1;
            int endMonth = endDate.Month - 1;
            string theURL = @"http://ichart.finance.yahoo.com/table.csv?s=" 
            + ticker + @"&a=" + startMonth.ToString() + @"&b=" + startDate.Day.ToString() 
            + @"&c=" + startDate.Year.ToString() + @"&d=" + endMonth.ToString() + @"&e=" + endDate.Day.ToString() 
            + @"&f=" + endDate.Year.ToString() + @"&g=d&ignore=.csv";

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(theURL);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            Stream resStream = response.GetResponseStream();
            StringBuilder sb = new StringBuilder();
            byte[] buf = new byte[8192];
            string tempString = null;
            int count = 0;

            do {
                count = resStream.Read(buf, 0, buf.Length);
                if (count != 0) {
                    tempString = Encoding.ASCII.GetString(buf, 0, count);
                    sb.Append(tempString);
                }
            }
            while (count > 0);
            string data = sb.ToString();
            String[] data2 = data.Split('\n');
            int iteration = 0;
            dates = new DateTime[data2.Length - 2];
            open = new double[data2.Length - 2];
            high = new double[data2.Length - 2];
            low = new double[data2.Length - 2];
            close = new double[data2.Length - 2];
            volume = new double[data2.Length - 2];
            adjClose = new double[data2.Length - 2];
            foreach (string strLine in data2)
            {
                String[] entries = strLine.Split(',');