I am performing an HttpRequest. It turns out that when I return the response and show it to work on it, it shows me this:
System.Threading.Tasks.Task`1[System.String]
My code is:
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace MLWPF.HttpRequest
{
class Client
{
private static readonly HttpClient httpClient = new HttpClient();
private FormUrlEncodedContent content;
public int Id { get; set; }
public int Uid { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public double Phone { get; set; }
public Client()
{
}
public Client(int id, int uid, string name, string address, double phone)
{
Id = id;
Uid = uid;
Name = name;
Address = address;
Phone = phone;
}
public async Task<string> ReadClients(int uid)
{
var values = new Dictionary<string, string>()
{
{"uid", uid.ToString()}
};
content = new FormUrlEncodedContent(values);
HttpResponseMessage response = await httpClient.PostAsync(new UrlHttpRequest().UrlReadClients, content);
string responseString = await response.Content.ReadAsStringAsync();
return responseString;
}
}
}
It turns out that if I show in the console before returning the responseString
, the information obtained is displayed correctly.
I am calling it from a method in the MainWindow.xaml.cs connected to a button.
private void FAB_Tab1_Button_Click(object sender, RoutedEventArgs e)
{
Client client = new Client();
client.ReadClients(1);
Console.WriteLine(client.Name);
}
How can I do so that when I return I get the information I need?