C# Stream 不断跳过第一行

C# Stream keeps skipping first line

好吧,我正在做一些应该相当简单的事情,我相信我在这里忽略了一些东西。

好吧,我使用 HttpWebRequest 和 WebResponse 来检测服务器上是否存在 Robots.txt(并且工作得很好)。但是,我正在尝试添加 myList.Add(reader.ReadLine());哪个(有效)。但问题是,它总是跳过第一行。

https://www.assetstore.unity3d.com/robots.txt < 那是我开始注意到问题的那个(只是为了让你知道我在说什么)。它仅用于测试目的。 (看看那个 link 这样您就可以了解我在说什么)。

任何人,它也没有将 reader.ReadLine 添加到我的列表中(仅第一行)。所以我不太明白发生了什么,我试着查了一下,我唯一发现的是故意跳过一行,我不想那样做。

下面是我的代码。

Console.WriteLine("Robots.txt Found: Presenting Rules in (Robot Rules).");
                HttpWebRequest getResults = (HttpWebRequest)WebRequest.Create(ur + "robots.txt");
                WebResponse getResponse = getResults.GetResponse();
                using (StreamReader reader = new StreamReader(getResponse.GetResponseStream())) {
                    string line = reader.ReadLine();
                    while(line != null && line != "#") {
                        line = reader.ReadLine();
                        rslList.Add(line);
                        results.Text = results.Text + line + Environment.NewLine; // At first I thought it might have been this (nope).
                    }


                    // This didn't work either (figured perhaps maybe it was skipping because I had to many things.
                    // So I just put into a for loop, - nope still skips first line.
                    // for(int i = 0; i < rslList.Count; i++) {
                    //     results.Text = results.Text + rslList[i] + Environment.NewLine;
                    // }
                }
                // Close the connection sense it is no longer needed.
                getResponse.Close();
                // Now check for user-rights.
                CheckUserRights();

结果图片。

更改下一次调用读取行的时间

var line = reader.ReadLine(); //Read first line
while(line != null && line != "#") { //while line condition satisfied
    //perform your desired actions
    rslList.Add(line);
    results.Text = results.Text + line + Environment.NewLine; 
    line = reader.ReadLine(); //read the next line
}