httpclient请求不断返回401&quort“ no Client Cert”从休息服务

发布于 2025-02-02 12:32:01 字数 934 浏览 3 评论 0原文

我在Xamarin表单中有一个问题,从iPhone Simulator上进行了一个.p12证书,从而在iPhone模拟器中进行了HTTPCLIENT帖子。它不断从休息服务中返回401“无客户证明”。我创建了一个具有相同代码的单独的控制台C#应用程序,并且效果很好,我从服务器上获得了200个响应以及预期的内容。我注意到的唯一区别是,C#控制台应用程序正在使用.NET Core 3.1,而Xamarin Forms应用程序使用的是.NET Standard 2.1,这是最新的。我将粘贴下面的代码,对任何帮助都表示感谢。

            string url = "https://ws.soa:8443/etav/jwt/encode";

            var handler = new HttpClientHandler();
            
            var certificate = new X509Certificate2("billyDillMacBook.p12", "test");
            handler.ClientCertificates.Add(certificate);
            handler.ServerCertificateCustomValidationCallback += (o, certificate, chain, errors) => true;
            using (HttpClient client = new HttpClient(handler))
            {
                
                HttpResponseMessage response = await client.PostAsync(url, null);
                var token = await response.Content.ReadAsStringAsync();
            }

I have a problem in Xamarin Forms making a HttpClient Post from the Iphone simulator with a .p12 certificate attached. It keeps returning 401 "No Client Cert" from the REST Service. I created a separate console C# application with the same code and it works fine, I get a 200 response from the server plus content which is expected. The only difference I note is that the C# console application is using .NET Core 3.1 and the Xamarin Forms app is using .NET Standard 2.1 which is the latest. I will paste the code below, any help is appreciated.

            string url = "https://ws.soa:8443/etav/jwt/encode";

            var handler = new HttpClientHandler();
            
            var certificate = new X509Certificate2("billyDillMacBook.p12", "test");
            handler.ClientCertificates.Add(certificate);
            handler.ServerCertificateCustomValidationCallback += (o, certificate, chain, errors) => true;
            using (HttpClient client = new HttpClient(handler))
            {
                
                HttpResponseMessage response = await client.PostAsync(url, null);
                var token = await response.Content.ReadAsStringAsync();
            }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文