简体   繁体   English

HttpListener服务器返回错误:(503)服务不可用

[英]HttpListener server returns an error: (503) Service Unavailable

I am trying to create a http listener that uses x509 certificates for client/server authentication. 我正在尝试创建一个使用x509证书进行客户端/服务器身份验证的http侦听器。

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. 没有证书策略错误,我已将ssl cert绑定到端口,并且不需要提升的权限来运行侦听器。

在此处输入图片说明

If I make a web request in code or through Chrome I get this error. 如果我使用代码或通过Chrome提出了Web请求,则会收到此错误。 What am I doing wrong here? 我在这里做错了什么?

在此处输入图片说明

事实证明,前缀不正确,一旦我将“ localhost”更改为“ +”,一切都可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM