.net 7 HTTP-запрос MAUI не получает ответаC#

Место общения программистов C#
Anonymous
.net 7 HTTP-запрос MAUI не получает ответа

Сообщение Anonymous »

При отправке http-запроса с помощью maui на Mac я не получаю ответа.
Вот приложение:

Код: Выделить всё

namespace vsfwefer;

using WeatherApp.Client.Services;
using WeatherApp.Client.Models;

public partial class MainPage : ContentPage
{
AccuWeatherService service;

public MainPage()
{
InitializeComponent();
service = new AccuWeatherService();
}

private async void OnCounterClicked(object sender, EventArgs e)
{
City[] cities = await service.GetLocations("Berlin");
Console.WriteLine("Got: " + cities[0].LocalizedName);
}
}
А вот и сервис:

Код: Выделить всё

using System.Text.Json;
using WeatherApp.Client.Models;

namespace WeatherApp.Client.Services
{
internal class AccuWeatherService : IAccuWeatherService
{
private HttpClient client;

private const string base_url = "http://dataservice.accuweather.com";

private const string autocomplete_endpoint = "locations/v1/cities/autocomplete?apikey={0}&q={1}&language{2}";

string api_key = "correctly";
string language = "pl";

public AccuWeatherService()
{
}

public async Task GetLocations(string locationName)
{
string uri = base_url + "/" + string.Format(autocomplete_endpoint, api_key, locationName, language);
Console.WriteLine("Calling for cities: " + uri);

using (var client = new HttpClient())
{
using (var r = await client.GetAsync(uri))
{
Console.WriteLine("Got content : " + r.Content);
string json = await r.Content.ReadAsStringAsync();
Console.WriteLine("Got json for cities: " + json);
City[] cities = JsonSerializer.Deserialize(json);
return cities;
}
}
}
}
Я не получаю никаких ошибок. просто информация о том, что тема началась, но я так и не получил ответа.
Он отлично работает с консольным приложением .net на том же компьютере. Это какое-то разрешение?

Подробнее здесь: https://stackoverflow.com/questions/773 ... e-response

Вернуться в «C#»