簡體   English   中英

HttpListener服務器返回錯誤:(503)服務不可用

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

我正在嘗試創建一個使用x509證書進行客戶端/服務器身份驗證的http偵聽器。

我的服務器代碼如下。

_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綁定到端口,並且不需要提升的權限來運行偵聽器。

在此處輸入圖片說明

如果我使用代碼或通過Chrome提出了Web請求,則會收到此錯誤。 我在這里做錯了什么?

在此處輸入圖片說明

事實證明,前綴不正確,一旦我將“ localhost”更改為“ +”,一切都可以正常工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM