title: HttpUrlConnection Cookies
body: <p>My Code is just working fine, but the server responds with 2 Set-Cookies. The problem is that the Session-ID is in the first one and the getHeaderField("Set-Cookie") only returns the last Set-Cookie. How can i get the first one ? Here is a picture of what i mean:</p>
  
  <p><a href="http://www.pic-upload.de/view-22334619/Unbenannt.png.html" rel="nofollow">http://www.pic-upload.de/view-22334619/Unbenannt.png.html</a></p>
  
  <pre><code>import java.awt.BufferCapabilities;
  import java.io.BufferedReader;
  import java.io.DataOutputStream;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.OutputStreamWriter;
  import java.io.UnsupportedEncodingException;
  import java.net.CookieHandler;
  import java.net.CookieManager;
  import java.net.HttpURLConnection;
  import java.net.MalformedURLException;
  import java.net.URL;
  
  import java.net.URLEncoder;
  import java.util.List;
  import java.util.Scanner;
  
  import javax.net.ssl.HttpsURLConnection;
  
  import org.omg.CORBA.portable.OutputStream;
  
  public class main {
  public static void main(String[] args) throws IOException {
  CookieHandler.setDefault(new CookieManager());
  String rawData = "";
  String type = "application/x-www-form-urlencoded";
  URL u = new URL("http://speed.die-kreuzzuege.de/index.php?action=login&amp;user=USERNAME&amp;pw=PW&amp;antibot=&amp;guest=&amp;check=");
  HttpURLConnection conn = (HttpURLConnection) u.openConnection();
  conn.setDoOutput(true);
  conn.setRequestMethod("POST");
  conn.setRequestProperty( "Content-Type", type );
  java.io.OutputStream os = conn.getOutputStream();
  
  String cookie = conn.getHeaderField("Set-Cookie");
      if (cookie != null)
             System.out.println("cookie: " + cookie)
  }
  }
  </code></pre>