title: How to get token in java
body: <p>I have the following implementation to get token from form authentication.</p>
  
  <p>The expected output is as follows:</p>
  
  <p><a href="https://i.stack.imgur.com/HafnM.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HafnM.jpg" alt="enter image description here"></a></p>
  
  <p>However, when I run my implementation, I am getting as follows.  In the response object, I do not see <code>token</code>.  I am not an expert on Java, I wonder what I am missing.</p>
  
  <pre><code>Login form get: HTTP/1.1 200 OK
  response: HttpResponseProxy{HTTP/1.1 200 OK [Cache-Control: max-age=0, Content-Type: application/json, Date: Fri, 04 Aug 2017 21:05:04 GMT, transaction_id: 729097fd-69ac-b813-26c7-015daf10ddfd, X-Powered-By: Express, Content-Length: 684, Connection: keep-alive] ResponseEntityProxy{[Content-Type: application/json,Content-Length: 684,Chunked: false]}}
  Post logon cookies:
  None
  </code></pre>
  
  <p>Here is the source code:</p>
  
  <pre><code>BasicCookieStore cookieStore = new BasicCookieStore();
  CloseableHttpClient httpclient = HttpClients.custom()
              .setDefaultCookieStore(cookieStore)
              .build();
  
  HttpHost proxy = new HttpHost("xxx.xxx.xxx.com", 80, "http");
  RequestConfig  config = RequestConfig.custom()
           .setProxy(proxy)
           .build();
  
  HttpUriRequest login = RequestBuilder.post()
       .setUri(new URI("https://api.xxx.com:443/tokens"))
       .addParameter("username", "stackoverflow")
       .addParameter("password", "isbest!")
       .setConfig(config)
       .build();
  
  CloseableHttpResponse response2 = httpclient.execute(login);
  HttpEntity entity = response2.getEntity();
  System.out.println("Login form get: " + response2.getStatusLine());
  
  EntityUtils.consume(entity);
  System.out.println("response: " + response2);
  
  System.out.println("Post logon cookies:");
  List&lt;Cookie&gt; cookies = cookieStore.getCookies();
  if (cookies.isEmpty()) {
      System.out.println("None");
  } else {
      for (int i = 0; i &lt; cookies.size(); i++) {
      System.out.println("- " + cookies.get(i).toString());
  }
  </code></pre>