C#流不断跳过第一行
好吧,我正在做一些应该很简单的事情,我相信我忽略了一些事情 好的,我使用HttpWebRequest和WebResponse来检测服务器上是否存在Robots.txt(这很好)。但是,我正在尝试添加以执行myList.add(reader.ReadLine());哪个有效。但问题是,它总是跳过第一行 <这就是我开始注意到问题的地方(只是想让你知道我在说什么)。这只是为了测试的目的。(看看那个链接,你就能知道我在说什么) 无论如何,它也没有将reader.ReadLine添加到我的列表中(仅第一行)。所以我不太明白到底发生了什么,我试着查了一下,我发现唯一的事情就是故意想跳过一行,我不想这样做 下面是我的代码C#流不断跳过第一行,c#,streamreader,webresponse,C#,Streamreader,Webresponse,好吧,我正在做一些应该很简单的事情,我相信我忽略了一些事情 好的,我使用HttpWebRequest和WebResponse来检测服务器上是否存在Robots.txt(这很好)。但是,我正在尝试添加以执行myList.add(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();
Console.WriteLine(“Robots.txt已找到:在(Robot Rules)中显示规则”);
HttpWebRequest getResults=(HttpWebRequest)WebRequest.Create(ur+“robots.txt”);
WebResponse getResponse=getResults.getResponse();
使用(StreamReader=newstreamreader(getResponse.GetResponseStream()){
字符串行=reader.ReadLine();
while(line!=null&&line!=“#”){
line=reader.ReadLine();
rslList.Add(行);
results.Text=results.Text+line+Environment.NewLine;//起初我以为可能是这样(不)。
}
//这也不起作用(我想可能是因为我有很多事情要做,所以跳过了)。
//所以我把它放进了一个for循环,-不,我还是跳过了第一行。
//for(int i=0;i
结果的图像。
下次调用读取行时更改
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
}
你正在扔掉第一个
string line=reader.ReadLine();
-将你的while
更改为do
/while
。谢谢你现在就去试试。谢谢你的帮助!嘿,谢谢你的帮助,我第一次尝试了Enigmatity(因为我第一次注意到它)他的建议奏效了……谢谢你的时间。@N1弹头-给恩科西打勾-他花时间实施了我的建议-节省了我的时间。:-)