Java HttpURLConnection no cookies at login
<p>I'm currently trying to do a login with HttpURLConnection and then get the session cookies...</p>

<p>I already tried that on some test pages on my own server, and that works perfectly. When i send <code>a=3&amp;b=5</code> i get <code>8</code> as cookie (PHP page adds both together)!
But when i try that at the other page, the output is just the page as if I just sent nothing with POST :(</p>

<p>General suggestions for improvement are welcome! :)</p>

<p>My Code:</p>

<pre><code>HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("useragent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0");
conn.setRequestProperty("Connection", "keep-alive");
DataOutputStream out = new DataOutputStream(conn.getOutputStream());
out.writeBytes("USER=tennox&amp;PASS=*****");
out.close();

BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
String response = new String();
while ((line = in.readLine()) != null) {
    response = response + line + "\n";
}
in.close();

System.out.println("headers:");
int i = 0;
String header;
while ((header = conn.getHeaderField(i)) != null) {
    String key = conn.getHeaderFieldKey(i);
    System.out.println(((key == null) ? "" : key + ": ") + header);
    i++;
}
String cookies = conn.getHeaderField("Set-Cookie");
System.out.println("\nCookies: \"" + cookies + "\"");
</code></pre>
