Код: Выделить всё
{
“errors": [
“Invalid API key”
]
}
Это код:< /p>
Код: Выделить всё
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace ApiRequest
{
///
/// Interaktionslogik für MainWindow.xaml
///
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Get_Place("").Wait();
}
static async Task Get_Place(string ip)
{
string path = "https://URI";
try
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(path);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
MessageBox.Show(path, "Path"); //Debug
HttpResponseMessage response = await client.GetAsync("api/clientnetwork");
MessageBox.Show("fertig", "fertig"); //Debug
if (response.IsSuccessStatusCode)
{
var jsonstring = response.Content.ReadAsStringAsync();
jsonstring.Wait();
//sto = JsonConvert.DeserializeObject(jsonstring.Result);
MessageBox.Show(jsonstring.ToString(), "Rückgabewert"); //Debug
//sto = await response.Content.ReadAsAsync(); - ReadAsAsync geht nicht
}
else
{
MessageBox.Show(response.StatusCode.ToString(), "Rückgabecode"); //Debug
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Fehler:");
}
}
}
}
HttpResponseMessage response = await client.GetAsync("api/clientnetwork");
< /code>
звонок, или, кажется, навсегда ждет ответа. Что я делаю не так?
Подробнее здесь: https://stackoverflow.com/questions/793 ... is-waiting