Откуда возникает эта проблема: При обращении к API с помощью httpclient, как показано ниже
Код: Выделить всё
var content = new StringContent(jsonData, Encoding.UTF8, "application/json");
var response = await _client.PostAsync(uri, content);
среда: .net 8, Android, Maui, Visual Studio.
Ситуация. Я обновил приложение Android Xamarin (.NET Framework) до MAUI.
Класс MainActivity:< /strong>
Код: Выделить всё
[Activity(Name = "Test.MainActivity", Label = "Test Mobile", Icon = "@drawable/icon"
, LaunchMode = LaunchMode.SingleTask, MainLauncher = true, ScreenOrientation = ScreenOrientation.Portrait, Theme = "@style/Maui.SplashTheme"
, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Microsoft.Maui.MauiAppCompatActivity
{
internal static MainActivity Instance { get; private set; }
// for FCM push notifications
internal static readonly string CHANNEL_ID = "fcm_notification_channel";
internal static readonly int NOTIFICATION_ID = 100;
enum EnvCheckType { Root, Debug, Emulator, Hooks, CustomFirmware, IntegrityCheck, WirelessSecurity };
static BitArray envChecks = new BitArray(7);
private MyBroadcastReceiver mMessageReceiver = new MyBroadcastReceiver();
protected override void OnCreate(Bundle savedInstanceState)
{
try
{
Instance = this;
base.OnCreate(savedInstanceState);
}
catch (Exception ex)
{
ExceptionLogger.LogErrorAsync(ex);
}
}
}
Код: Выделить всё
[Application]
public class MainApplication : MauiApplication
{
// for FCM push notifications
internal static readonly string CHANNEL_ID = "fcm_notification_channel";
internal static readonly int NOTIFICATION_ID = 100;
enum EnvCheckType { Root, Debug, Emulator, Hooks, CustomFirmware, IntegrityCheck, WirelessSecurity };
static BitArray envChecks = new BitArray(7);
public MainApplication(nint handle, JniHandleOwnership ownership) : base(handle, ownership)
{
}
protected override MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder.UseMauiApp().UseMauiCommunityToolkit();
return builder.Build();
}
}
Подробнее здесь: https://stackoverflow.com/questions/784 ... ted-ensure