HttpRequest Head and Body




    The code above first creates an instance of the HttpWebRequest class, using the string site as the input. It then uses the HttpWebRequest.Create() method to create a request to the website. The HttpWebResponse object that is returned from this request contains the body of the response sent from

    The code uses the StreamReader class to read the entire body of the response, line by line. The textText variable is populated with the contents of each line in the response.

    using System;
    using System.Net;
    using System.IO;
    public class Program
      public static void Main()
      string site = "";
      HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(site);
      HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
      using (StreamReader stream = new StreamReader(resp.GetResponseStream()))
        var txb_textText = stream.ReadToEnd();
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.