HttpListener服务器返回错误:(503)服务不可用 [英] HttpListener server returns an error: (503) Service Unavailable
本文介绍了HttpListener服务器返回错误:(503)服务不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建一个使用x509证书进行客户端/服务器身份验证的http侦听器.
I am trying to create a http listener that uses x509 certificates for client/server authentication.
我的服务器代码如下.
_listener = new HttpListener();
_listener.Prefixes.Add("https://localhost:8006/");
_listener.Start();
HttpListenerContext context = _listener.GetContext();
我的客户代码如下
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();
我相信我已经正确配置了所有内容.没有证书策略错误,我已经将ssl cert绑定到了端口,并且不需要提升的权限来运行侦听器.
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.
如果我使用代码或通过Chrome提出了Web请求,则会收到此错误.我在这里做什么错了?
If I make a web request in code or through Chrome I get this error. What am I doing wrong here?
推荐答案
一旦我将"localhost"更改为"+",结果前缀是不正确的.
Turns out the prefix was incorrect, once I changed 'localhost' to '+' everything worked fine.
这篇关于HttpListener服务器返回错误:(503)服务不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文