I'm making use of an API. I authenticate via that API with an access token that I send into the header. Now when I try to load some content into an HtmlWebViewSource
, for instance an image, there is nothing loaded. This is because the request it does to the images, won't add any headers to the requests. The code I currently have is:
On my ViewModel:
public class ArticleViewModel : BaseViewModel
{
private HtmlWebViewSource _body;
public const string BodyPropertyName = "Body";
public HtmlWebViewSource Body {
get { return _body; }
set { this.SetProperty(ref _body, value, BodyPropertyName); }
}
private async void ExecuteLoadArticleCommand(string id)
{
if (IsBusy)
return;
IsBusy = true;
try
{
var article = ""; // article.Body contains a long HTML string with img tags in it.
Body = new HtmlWebViewSource
{
Html = article.Body
};
}
catch (Exception exception)
{
var page = new ContentPage();
page.DisplayAlert("Error", string.Format("{0}", exception.Message), "Ok");
}
IsBusy = false;
}
}
On my ArticleView, I got the following inialization of a WebView:
private WebView GetArticleWebLayout()
{
var browser = new WebView();
browser.SetBinding(WebView.SourceProperty, "Body");
return browser;
}
How to intercept the requests that the WebView
does and add the headers to it?