我想知道C#中是否有办法获得&阅读HTTP Web响应,但只能达到某一点。例如:
public static void Example()
{
HttpWebRequest request = (HttpWebRequest)WebRequest.CreateHttp("http://www.example.com/");
using(HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using(Stream responseStream = response.GetResponseStream())
{
using(StreamReader responseReader = new StreamReader(responseStream, System.Text.Encoding.UTF8))
{
string line;
while((line = responseReader.ReadLine()) != null)
{
if(line.Contains("stop!"))
{
break;
}
}
}
}
}
}
这将阻止流阅读,但响应仍然是整个页面,而不仅仅是到达"停止!"找到了。