Код: Выделить всё
private static HttpClient client;
private static JsonSerializerOptions options;
public static string BaseAddress =
DeviceInfo.Platform == DevicePlatform.Android ? "http://10.0.2.2:5000" : "http://localhost:5000";
private static readonly string MeetmanUrl = $"{BaseAddress}/api/meetman/getall";
public ApiServiceListUser()
{
client = new HttpClient();
options = new JsonSerializerOptions()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = true,
};
}
public async Task GetMeetmanAsync()
{
await Task.Delay(500); // Simulate delay
Meetmans = [];
try
{
HttpResponseMessage response = await client.GetAsync(BaseAddress);
if (response.IsSuccessStatusCode)
{
var respons = await client.GetAsync(client.BaseAddress);
respons.EnsureSuccessStatusCode();
var json = await response.Content.ReadAsStringAsync();
return JsonSerializer.Deserialize(json, options);
//string content = await response.Content.ReadAsStringAsync();
//Meetmans = JsonSerializer.Deserialize(content, options);
}
}
catch (Exception ex)
{
Debug.WriteLine(@"\tERROR {0}", ex.Message);
}
return Meetmans;
}
public List Meetmans { get; set; } = [];
Код: Выделить всё
[Application(UsesCleartextTraffic = true)]
public class MainApplication : MauiApplication
{
public MainApplication(nint handle, JniHandleOwnership ownership)
: base(handle, ownership)
{
}
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... -localhost
Мобильная версия