[英]How to understand the difference between Windows/.NET and Linux/Mono with a .NET WebRequest and a PFX certificate?
我目前正在使用使用客戶端證書身份驗證的API。 我有一個簡單的代碼塊,可以在Linux / Mono下工作。 在Windows / .NET下執行時,我收到200,但是響應內容提示我需要證書才能進行此調用。
ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
var x509 = new X509Certificate2("foo.pfx", "test");
var request = (HttpWebRequest)WebRequest.Create("https://domain.com:8081");
request.Method = "POST";
request.ClientCertificates.Add(x509);
const string data = "{\"foo\":\"bar\"}";
var postdata = Encoding.ASCII.GetBytes(data);
request.ContentLength = data.Length;
var myStream = request.GetRequestStream();
myStream.Write(postdata, 0, postdata.Length);
var response = (HttpWebResponse)request.GetResponse();
Console.WriteLine(new StreamReader(response.GetResponseStream()).ReadToEnd());
在兩種情況下都使用相同的foo.pfx。 有誰知道我如何解釋結果的差異?
是否有一些重定向? 如果是,則MSDN說:
自動重定向上的Authorization標頭已清除,並且HttpWebRequest自動嘗試重新認證到重定向的位置。 實際上,這意味着如果可能遇到重定向,則應用程序無法將自定義身份驗證信息放入Authorization標頭中。 而是,應用程序必須實現並注冊自定義身份驗證模塊。 System.Net.AuthenticationManager和相關類用於實現自定義身份驗證模塊。 AuthenticationManager.Register方法注冊自定義身份驗證模塊。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.