.NET HttpListener: when registering HTTP and HTTPS, I get "conflicts with existing registration on the machine",

I am trying to use the .NET HttpListener in a C # project. When I register my prefix "http: // *: 8080 /", it does not work for HTTPS URLs (i.e. Does not pick them up). When I try to use the following code to register both HTTP and HTTPS versions of the prefix, however, I get an error:

"Could not listen to the prefix" https: //: 8080 / "because it conflicts with existing registration on the computer."

How can I get the prefix for HTTP and HTTPS?

private HttpListener _listener; // Create prefixes var prefixes = new List<string>(); prefixes.Add("http://*:8080/"); prefixes.Add("https://*:8080/"); // Create HttpListener _listener = new HttpListener(); foreach (string prefix in prefixes) { _listener.Prefixes.Add(prefix); } _listener.Start(); // <== ERROR HERE 

EDIT 1 - Additional clarification:

  • The program acts as a local proxy server for PC applications that make HTTP (S) calls.
  • Therefore, the use is based on changing the settings of the browser proxy server to point to this local home proxy server (for example, localhost: 8080).
  • This means, therefore (I believe), that the HttpListener should listen for both HTTP and HTTPS traffic on the same local port (for example, 8080).
  • PURPOSE: try to find a way for my program to listen on both HTTP and HTTPS on the same port .

thanks

+6
source share
5 answers

PURPOSE: try to find a way for my program to listen on both HTTP and HTTPS on the same port.

You cannot do this with HTTPListener. You will need to use a TCPListener and process each response conditionally depending on whether it is HTTP or HTTPS.

I am sure that if you use one HTTPListener for HTTP 8080 and one for HTTPS 8443, you must make your browser to use your proxy: 8080 for HTTP and yourproxy: 8443 for HTTPS. Firefox definitely allows you to do this.

+8
source

By default, https uses port 443 rather than 80. You must specify a different port for a different lister protocol.

+3
source

It sounds nontrivial, but not impossible. You will need to check what the client sends and decide whether they are starting an HTTP or HTTPS session based on the data that they provide.

edit: Thinking about it a bit more, this is probably not what you want to do, given that you are writing proxies. Instead, you will need to process the CONNECT method (see http://www.ietf.org/rfc/rfc2817.txt ) and open a tunnel connection to the target server.

+2
source

"If you create an HttpListener using https, you must select a server certificate for this listener. Otherwise, the HttpWebRequest request for this HttpListener will terminate with an unexpected connection closure." This is from the msdn website. ( http://msdn.microsoft.com/en-us/library/system.net.httplistener.aspx ) Maybe there is a problem?

+2
source

You should not use the same configuration for all protocols.

The hit advanced in the proxy server settings, and there you can specify different proxy server settings for other protocols.

0
source

All Articles