title: How to set 'Referer' HTTP header using Apache HttpComponents HttpClient
body: <p>I wrote php curl to request some data from my API server, and now I want to develop a JSP to request the data from the same API server.</p>
  
  <p>The problem comes when my API server need http referer to check if the request come from a valid url.</p>
  
  <p>My original PHP is:</p>
  
  <pre><code>$ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, 'http://www.example.com/2');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_REFERER, 'http://www.example.com/1');
  $html = curl_exec($ch);
  </code></pre>
  
  <p>... then my api server get the referer url with</p>
  
  <pre><code>var_dump($_SERVER['HTTP_REFERER'])
  </code></pre>
  
  <p>How do I use Apache HttpComponents HttpClient to set the <code>Referer</code> header?</p>