相关疑难解决方法(0)

从Android模拟器访问localhost:port

我正在运行的本地计算机上运行Web服务localhost:54722.

我想从Android模拟器中运行的应用程序调用该服务.

我读到10.0.2.2在应用程序中使用将访问localhost,但它似乎也不适用于端口号.它说HttpResponseException: Bad Request.

port android localhost android-emulator

200
推荐指数
11
解决办法
16万
查看次数

“找不到认证路径的信任锚。” 在 .NET Maui 项目中尝试联系本地 .NET WebApi

我是移动开发新手,我正在尝试将我的 .NET Maui 应用程序连接到本地 ASP.NET Core 网站 (API)。

我目前被此异常阻止:

System.Net.WebException: 'java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.'

我已关注这篇文章https://learn.microsoft.com/en-us/xamarin/cross-platform/deploy-test/connect-to-local-web-services#bypass-the-certificate-security-check

运行dotnet dev-certs https --trust回报A valid HTTPS certificate is already present.

我当前的代码是:

HttpClientHandler handler = new HttpClientHandler();
handler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) =>
  {
     if (cert.Issuer.Equals("CN=localhost"))
          return true;
     return errors == System.Net.Security.SslPolicyErrors.None;
  };

var httpclient = new HttpClient(handler);
var test = await httpclient.PostAsync($"https://10.0.2.2:44393/" + uri, new StringContent(serializedItem, Encoding.UTF8, "application/json"));
Run Code Online (Sandbox Code Playgroud)

但问题是我从未输入 ServerCertificateCustomValidationCallback。

我也尝试过

        ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, …
Run Code Online (Sandbox Code Playgroud)

c# ssl-certificate xamarin asp.net-core maui

12
推荐指数
1
解决办法
1万
查看次数