HttpListener server returns an error: (503) Service Unavailable

血红的双手。 提交于 2019-12-10 11:54:09

问题


I am trying to create a http listener that uses x509 certificates for client/server authentication.

My server code is as follows.

_listener = new HttpListener();
_listener.Prefixes.Add("https://localhost:8006/");
_listener.Start();
HttpListenerContext context = _listener.GetContext();

My client code is as follows

string url = "https://localhost:8006/";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
var store = new X509Store(StoreName.TrustedPeople, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly);
var cert = store.Certificates.Find(X509FindType.FindBySubjectName, "localhost", true);
request.ClientCertificates.Add((X509Certificate)cert[0]);
ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, policyErrs) =>
   {
       return policyErrs == System.Net.Security.SslPolicyErrors.None;
   };
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

I believe I have configured everything correctly. There are no certificate policy errors, I have bound the ssl cert to the port, and require no elevated permissions to run the listener.

If I make a web request in code or through Chrome I get this error. What am I doing wrong here?


回答1:


Turns out the prefix was incorrect, once I changed 'localhost' to '+' everything worked fine.



来源:https://stackoverflow.com/questions/26412602/httplistener-server-returns-an-error-503-service-unavailable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!