How can I get the HTTP portion of the HTTP response in C #

I am wondering if there is a way in C # to get and read an HTTP HTTP response, but only up to a certain point. Example:

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;
                    }
                }
            }
        }
    }
}

      

This will stop the stream from reading, but the response is still a solid page, not just until "stop!"

+3


source to share





All Articles