title: Retrieve cookie and send it in subsequent POST requests
body: <p>I want to read two numbers (randomly generated) from a website which are then used in order to compute a result and then submit the result using a POST request. To do so, I will also need to submit the cookie of that session so that the system is aware of the random numbers which have been produced in that particular session. </p>
  
  <p>In order to read the numbers I am using <code>Jsoup</code>: </p>
  
  <pre><code>Document document = Jsoup.parse(Jsoup.connect("http://website.com/getNumbers").get().select("strong").text());
  String[] numbers = document.text().split(" ");
  String answer = methodThatComputesTheDesiredOutput(numbers);
  </code></pre>
  
  <p>Now I want to send a POST request that includes <code>answer</code> and <code>cookies</code> of that session. Here's a partially implemented POST request that includes only the one parameter (<code>answer</code>):  </p>
  
  <pre><code>HttpClient httpClient = HttpClients.createDefault();
  HttpPost httpPost = new HttpPost("http://website.com/submitAnswer");
  List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;(1);
  params.add(new BasicNameValuePair("answer", answer);
  httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
  </code></pre>
  
  <p>How can I obtain the cookie when reading the document and then use it as a parameter of the POST request? </p>