title: Get cookie from request header java
body: <p>I am trying to get a <code>sessionid</code>cookie that you would when inspecting a web page. For example, on Chrome right-click the page > inspect > Network > (refresh with F5)</p>
  
  <p>I am trying to use the URLConnection library like so:</p>
  
  <pre><code>URLConnection connection = new URL("http://website.com/link/to/some_wsdl?wsdl").openConnection();
  </code></pre>
  
  <p>The fields inside <code>connection</code> are the following:</p>
  
  <p>Request:</p>
  
  <pre><code>keys:
   0 = "GET /link/to/some_wsdl?wsdl HTTP/1.1"
   1 = "User-Agent"
   2 = "Host"
   3 = "Accept"
   4 = "Connection"
  values:
   1 = "Java/1.8.0_131"
   2 = "iccdev.ejgallo.com"
   3 = "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
   4 = "keep-alive"
  </code></pre>
  
  <p>Response:</p>
  
  <pre><code>keys:
   1 = "Date"
   2 = "Server"
   3 = "X-Powered-By"
   4 = "Keep-Alive"
   5 = "Connection"
   6 = "Transfer-Encoding"
   7 = "Content-Type"
   8 = "Content-Language"
  values:
   0 = "HTTP/1.1 200 OK"
   1 = "Tue, 20 Jun 2017 00:35:53 GMT"
   2 = "Oracle-Application-Server-11g"
   3 = "Servlet/2.5 JSP/2.1"
   4 = "timeout=5, max=100"
   5 = "Keep-Alive"
   6 = "chunked"
   7 = "text/xml; charset=utf-8"
   8 = "en"
  </code></pre>
  
  <p>The problem is that I'm missing a sessionid entry that should be in the request headers with the prefix <code>distsite=SESSIONID=</code></p>
  
  <hr>
  
  <p>EDIT: It's been a while since I asked this question, but I'll leave this here anyways in case someone else has a similar issue.</p>
  
  <p>Essentially, the cookie I was looking for was one that is used internally by our custom implementation of LDAP and it is only created by authenticating with said LDAP implementation. The cookie is used for SSO (Single Sign-On), and therefore would be easily obtained by the browser via the standard protocols. Since I was using Java to get it without properly authenticating, I would not get the cookie back in the response from our call to the LDAP API.</p>