I'd like to use a HttpClient in a shared C# class. I've seen the HttpClient in a few Xamarin examples like this one: http://docs.xamarin.com/guides/cross-platform/advanced/async_support_overview
But somehow I cannot use "using System.Net.Http;" and I guess therefore HttpClient won't work as it's an unknown object.
Any ideas?
My code:
using System;
using System.IO;
using System.Net;
using System.Threading.Tasks;
using MyApp.Shared;
namespace MyApp.Shared
{
public class FileDownloader
{
public byte[] GetFile {get; private set;}
public async Task<bool> DownloadFile(string uri)
{
try
{
var httpClient = new HttpClient(); // Error CS0246: The type or namespace name `HttpClient' could not be found. Are you missing an assembly reference? (CS0246)
this.GetFile = await httpClient.GetByteArrayAsync(uri);
}
catch (OperationCanceledException)
{
Debug.LogWarning("File download got canceled.", "FileDownloader");
return false;
}
return true;
}
}
}