0

I've created a small app to get http/https responses:

        public static void Listener1(string[] prefixes)
        {
            if (!HttpListener.IsSupported)
            {
                Console.WriteLine("Seu ambiente não suporta os recursos da classe HttpListener.");
                return;
            }
            if (prefixes == null || prefixes.Length == 0)
                throw new ArgumentException("prefixes");
            HttpListener listener = new HttpListener();
            foreach (string s in prefixes)
            {
                listener.Prefixes.Add(s);
            }
            listener.Start();
            Console.WriteLine("Listening...");
            HttpListenerContext context = listener.GetContext();
            HttpListenerRequest request = context.Request;
            HttpListenerResponse response = context.Response;
            string responseString = "<HTML><BODY> Hello world </BODY></HTML>";
            byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
            response.ContentLength64 = buffer.Length;
            System.IO.Stream output = response.OutputStream;
            output.Write(buffer, 0, buffer.Length);
            output.Close();
            listener.Stop();
        }

And I'm using this prefixes:

string[] url = { "http://localhost:5324/", "https://localhost:5325/" };

When I type http://localhost:5324/ on Chrome, I get the right response, but when using https://localhost:5325/, nothing happens. Not even errors about certificates.

GPGomes
  • 117
  • 2
  • 13
  • https in localhost will throw an error if you don't have a self signed certificate... Maybe you have the errors disabled and it just doesn't show the certificate error – Carlos Alves Jorge May 07 '19 at 19:02
  • I've created a self signed certifcate using: New-SelfSignedCertificate -DnsName localhost -CertStoreLocation cert:\LocalMachine\My and still have the same problem – GPGomes May 07 '19 at 20:19
  • 1
    I have recently implement HTTPS using HTTPListener. I have shared my solution here: https://stackoverflow.com/a/58149405/983548 – Habib Sheikh Sep 28 '19 at 21:00

0 Answers0