我怎样才能在C#中收到部分HTTP Web响应

时间:2015-07-07 18:58:47

标签: c# stream httpwebrequest readline httpwebresponse

我想知道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;
                    }
                }
            }
        }
    }
}

这将阻止流阅读,但响应仍然是整个页面,而不仅仅是到达"停止!"找到了。

0 个答案:

没有答案