JavaでHttpsUrlConnectionを使用してWebサイト(https://account.mojang.com/login)からCookieを受信しようとしていますが、応答としてCookieを送信しません。驚くべきことは、Apache HttpClientなどのライブラリがCookieを受信できることです。 Pythonのリクエストライブラリでも動作します。Java HTTP Cookieが受信されません
マイコード:
URL obj = new URL("https://account.mojang.com/login");
HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Host", "account.mojang.com");
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
con.setRequestProperty("Content-Length", Integer.toString(postPARAMS.length()));
//System.out.println(Integer.toString(postPARAMS.length()));
//con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0");
//con.setRequestProperty("Connection", "keep-alive");
//con.setRequestProperty("Accept-Encoding", "gzip, deflate");
con.setRequestProperty("Accept", "*/*");
// For POST only - START
con.setDoOutput(true);
OutputStream os = con.getOutputStream();
os.write(postPARAMS.getBytes());
os.flush();
os.close();
// For POST only - END
System.out.println("POST Response Code :: " + con.getResponseCode());
上記のコードクッキーを受信しません。私はそれが働いていることを確認しましたが、クッキーは空です。 Apache HttpClientを使用すると、Cookieは空ではありません。 Apacheのコードは次のとおりです。
final HttpClient client = HttpClientBuilder.create().build();
final HttpPost loginPost = new HttpPost("https://account.mojang.com/login");
loginPost.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36");
final List<NameValuePair> loginParams = new ArrayList<NameValuePair>();
loginParams.add(new BasicNameValuePair("username", email));
loginParams.add(new BasicNameValuePair("password", password));
loginPost.setEntity(new UrlEncodedFormEntity(loginParams));
client.execute(loginPost);
PythonのリクエストライブラリでもCookieが受信されます。私は、ヘッダーでクッキーを受け取ることができるhttp://requestmaker.com/で送られたヘッダーを見ることもテストしました。 requestmaker.comと同じヘッダーを使用しても、私はまだクッキーを受け取ることができません。
質問は次のとおりです。これらのライブラリは、私のHttpsUrlConnectionにはないものは何ですか?