我在这里下载了最新的示例MAUI:https://github.com/microsoft/dotnet-podcasts,并复制了它们发出请求的确切方式,但我无法通过"意外的流结束错误":
System.Net.WebException: unexpected end of stream on com.android.okhttp.Address@4c288121
---> Java.IO.IOException: unexpected end of stream on com.android.okhttp.Address@4c288121
我正在初始化MauiProgram中的HttpClient
.cs通过AddHttpClient
出厂方法,如so(注意ANDROID的不同IP地址):
public static string Base = DeviceInfo.Platform == DevicePlatform.Android ? "http://10.0.2.2" : "https://localhost";
public static string APIUrl = $"{Base}:7096/api/";
builder.Services.AddHttpClient<DishClient>(client => { client.BaseAddress = new Uri(APIUrl); });
我在AndroidManifest中包含了以下android:networkSecurityConfig
个.xml(允许http通信):
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>
Xamarin中的解决方案似乎是使用AndroidClientHandler
,但这是在一个不推荐使用的库中,我无法在MAUI中使用,并且在有效的链接解决方案中没有对它的引用.
Things I've tried:
使用Https:我遵循了此处的指南:https://docs.microsoft.com/en-us/xamarin/cross-platform/deploy-test/connect-to-local-web-services#bypass-the-certificate-security-check,但仍会收到证书错误:
System.Net.WebException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
---> Javax.Net.Ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
我也试过这个
handler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
但是得到一个错误
System.PlatformNotSupportedException: Operation is not supported on this platform
已经连续4天了,我已经判断了工作解决方案中所有可能的设置,没有发现任何差异.有什么 idea 吗?