HTML Minifier C# Example

Check the example on how to use
C#
to minify a HTML hardcoded string and output to stdout:
using System;
using System.Net;
using System.Text;
using System.IO;
using System.Diagnostics;

public class Program
{
    public static void Main()
    {
        var content = "<input type="text" />";
        var request = (HttpWebRequest)WebRequest.Create("https://www.toptal.com/developers/html-minifier/api/raw");
        request.Method = "POST";
        string formContent = "input=" + content;
        byte[] byteArray = Encoding.UTF8.GetBytes(formContent);
        request.ContentType = "application/x-www-form-urlencoded";
        request.ContentLength = byteArray.Length;

        Stream str = request.GetRequestStream();
        str.Write(byteArray, 0, byteArray.Length);
        str.Close();

        WebResponse response = request.GetResponse();
        str = response.GetResponseStream();
        if (str != null)
        {
          StreamReader reader = new StreamReader(str);
          var minified = reader.ReadToEnd();
          Console.WriteLine(minified);
          reader.Close();
          str.Close();
        }
        response.Close();
    }
}
Copy this to your
Program.cs
file of your project and run the following command:
dotnet run

Output:

<input>