title: java send GET/POST requests while maintaining cookies
body: <p>I'm using Apache HttpClient 4.2.5 and I'm trying to send GET/POST requests while passing cookies from one request to another (like a real browser would).</p>
  
  <pre><code>HttpClient client = new DefaultHttpClient();
  HttpGet request = new HttpGet(get_url);
  
  request.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:22.0) Gecko/20100101 Firefox/22.0");
  request.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
  request.setHeader("Accept-Language", "en-US,en;q=0.5");
  request.setHeader("Connection", "keep-alive");
  
  try {
       HttpResponse response = client.execute(request);
       // Get cookies &amp; pass them to a POST request
  } catch (IOException e) {
       System.out.println("Error: " + e.getMessage());
  }
  </code></pre>
  
  <p>Is there anything that resembles PHP's cURL functionality? cURL is simple and straightforward but it's so hard to find a working piece of code on Google that does what I need in Java.</p>
  
  <p>What I want is very simple. Let me send POST and GET requests. At the same time, pass the cookies and let me set my own headers. Anything like that in Java?</p>