I'm currently playing around with Hololens and Hololens-programming. For my task I need to communicate with my REST API and build some stuff with the data.
I'm trying to use the HttpClient for my task.
I installed it with Install-Package Microsoft.AspNet.WebApi.Client
, so it works, when I'm in Visual Studio 2017 for editing the scripts. The Namespace System.Net.Http
works fine.
But when I switch to Unity, it keeps telling me the following:
Assets/Scripts/RestClient.cs(77,46): error CS1061: Type 'System.Net.Http.HttpContent' does not contain a definition for 'ReadAsAsync' and no extension method 'ReadAsAsync' of type 'System.Net.Http.HttpContent' could be found. Are you missing an assembly reference?
It references this code snippet from the microsoft documentation I linked before:
static async Task<Product> GetProductAsync(string path)
{
Product product = null;
HttpResponseMessage response = await client.GetAsync(path);
if (response.IsSuccessStatusCode)
{
product = await response.Content.ReadAsAsync<Product>();
}
return product;
}
It simply says, there is no ReadAsAsync<T>()
, but it works in Visual Studio 2017 and it's in the docu. I'm so confused right know.
I'm trying to solve this already almost the whole day.
Already did: this