title: HttpClient: "HttpRequestException: An error occurred while sending the request"
body: <p>I'm trying to get a image using HttpClient and I'm getting this error:</p>
  <blockquote>
  <p>HttpRequestException: An error occurred while sending the request</p>
  </blockquote>
  <p>Using WebClient with DownloadData method, works fine.</p>
  <pre><code>var cookieContainer = new CookieContainer();
  using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer })
  using (var client = new HttpClient(handler))
  {
      client.DefaultRequestHeaders.Add(&quot;User-Agent&quot;, &quot;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36&quot;);
      client.DefaultRequestHeaders.Add(&quot;Accept&quot;, &quot;text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8&quot;);
      client.DefaultRequestHeaders.Add(&quot;Accept-Encoding&quot;, &quot;gzip, deflate&quot;);
      client.DefaultRequestHeaders.Add(&quot;User-Agent&quot;, &quot;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36&quot;);
      client.DefaultRequestHeaders.Add(&quot;Accept-Language&quot;, &quot;pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4&quot;);
      client.DefaultRequestHeaders.Add(&quot;Upgrade-Insecure-Requests&quot;, &quot;1&quot;);
      client.GetAsync(&quot;cookieGenerateUrl&quot;).Wait();
  
      client.DefaultRequestHeaders.Remove(&quot;Accept&quot;);
      client.DefaultRequestHeaders.Add(&quot;Accept&quot;, &quot;image/webp,image/apng,image/*,*/*;q=0.8&quot;);
      var imagem = client.GetByteArrayAsync(imageUrl).Result;
  }
  </code></pre>
  <p>What is the equivalent to WebClient.DownloadData on HttpClient class?</p>