Load an image from URL as base64 string
<p>I am trying to load an image as a base 64 string so that i can show it in a html like this:</p>

<pre><code> &lt;html&gt;&lt;body&gt;&lt;img src="data:image/jpeg;base64,/&gt;&lt;/img&gt;&lt;/body&gt;&lt;/html&gt;
</code></pre>

<p>Heres my code so far, but it does not really work:</p>

<pre><code>   public async static Task&lt;string&gt; getImage(string url)
   {
    var request = (HttpWebRequest)WebRequest.Create(url);
   request.Accept = "data:image/jpg;charset=base64";
   request.Credentials = new NetworkCredential(user, pw);
   using (var response = (HttpWebResponse)(await Task&lt;WebResponse&gt;.Factory.FromAsync(request.BeginGetResponse, request.EndGetResponse, null)))
        {
            StreamReader sr = new StreamReader(response.GetResponseStream());
            return sr.ReadToEnd();
        }
</code></pre>

<p>I tried using this method i found elsewhere to encode the return-String as base64, but when placing it in a html the image just shows the typical placeholder.</p>

<pre><code>    public static string Base64Encode(string plainText)
    {
        var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
        return System.Convert.ToBase64String(plainTextBytes);
    }
</code></pre>

<p>EDIT:</p>

<p>Here is how the html looks: 
<a href="https://i.stack.imgur.com/MTrS4.png" rel="noreferrer"><img src="https://i.stack.imgur.com/MTrS4.png" alt="enter image description here"></a></p>