2014-10-16 134 views
0

我正在尝试创建一个使用x509证书进行客户端/服务器身份验证的http侦听器。HttpListener服务器返回错误:(503)服务不可用

我的服务器代码如下。

_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证书绑定到端口,并且不要求提升权限来运行侦听器。

enter image description here

如果我让代码或通过Chrome的Web请求我得到这个错误。我在这里做错了什么?

enter image description here

+0

你尝试过使用netsh http命令吗?也许你是8006的端口已经在使用..也做了以下谷歌搜索[导致httpListener错误503](http://stackoverflow.com/questions/8142396/what-c​​auses-a-httplistener-http -503-错误) – MethodMan 2014-10-16 19:52:53

+0

我已将端口号更改为30001,我确定它是免费的,并获得了相同的结果。 – 2014-10-17 20:32:40

回答

2

原来的前缀是不正确的,一旦我改变的“localhost”到“+”一切正常。

相关问题