我正在运行的本地计算机上运行Web服务localhost:54722.
我想从Android模拟器中运行的应用程序调用该服务.
我读到10.0.2.2在应用程序中使用将访问localhost,但它似乎也不适用于端口号.它说HttpResponseException: Bad Request.
我是移动开发新手,我正在尝试将我的 .NET Maui 应用程序连接到本地 ASP.NET Core 网站 (API)。
我目前被此异常阻止:
System.Net.WebException: 'java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.'
运行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)