如何在 .NET MAUI 安卓中开启 HTTP 明文传输

本指南介绍了如何在 .NET MAUI 安卓应用中通过在 MainApplication.cs 文件中设置 `UsesCleartextTraffic=true` 来允许 HTTP 明文传输。

Platforms/Android/MainApplication.cs文件添加明文属性

1
2
3
4
5
6
7
8
9
#if DEBUG                                   // connect to local service on the
[Application(UsesCleartextTraffic = true)]  // emulator's host for debugging,
#else                                       // access via http://10.0.2.2
[Application]                               
#endif
public class MainApplication : MauiApplication
{
    ...
}
Built with Hugo
Theme Stack designed by Jimmy