The Picasso library on NuGet and the Xamarin Component store is super old. It hasn't been updated in over a year. Hence there might be slight differences from the code you see out there from what you have available.
If you need to add a header to your image requests you can implement your own IDownloader
which you hand to Picasso:
public class CustomDownloader : OkHttpDownloader
{
public CustomDownloader(IntPtr handle, JniHandleOwnership transfer)
: base(handle, transfer)
{ }
public CustomDownloader(string authtoken, Context context) : base(context)
{
Client.Interceptors().Add(new MyInterceptor(authtoken));
}
public class MyInterceptor : Java.Lang.Object, IInterceptor
{
private string _authtoken;
public MyInterceptor(string authtoken)
{
_authtoken = authtoken;
}
public Response Intercept(IInterceptorChain chain)
{
var newRequest = chain.Request().NewBuilder().AddHeader("Authentication", _authtoken).Build();
return chain.Proceed(newRequest);
}
}
}
You can then add this custom downloader like:
var token = "authtoken";
var builder = new Picasso.Builder(this).Downloader(new CustomDownloader(token, this)).Build();
Then as usual you can download your image into an ImageView
as usual with:
builder.Load(Android.Net.Uri.Parse("https://test.com/img.jpg")).Into(imageView);
I've tested this against Requestb.in and the Authentication
header is set just fine.
You can obviously set any header you want.