如何从 Xamarin 中的 WebAPI 获取结果值

How to get result value from WebAPI in Xamarin

public async Task<Customer> GetCustomersAsync(string id)
    {
        var prod = new Customer();
        HttpClient client = new HttpClient();
        string url = "https://xxxxxx.com/api/Customers/" + id;
        client.BaseAddress = new Uri(url);
        HttpResponseMessage response = await client.GetAsync("");
        if (response.IsSuccessStatusCode)
        {
            string content = response.Content.ReadAsStringAsync().Result;
            prod = JsonConvert.DeserializeObject<Customer>(content);
        }
        return await Task.FromResult(prod);
    }

我打电话给 API 以获取结果。但是当 .Result

时我无法得到 return 结果

我是这样做的:

var infocustomer = customerRepository.GetCustomersAsync(userrating);
string nameus = infocustomer.Result.NameUs;

而不是这个

string content = response.Content.ReadAsStringAsync().Result;

这样做

string content = await response.Content.ReadAsStringAsync();

然后

return prod;