如何解密HttpsURLConnection

时间:2014-11-19 08:11:09

标签: java encryption response httpsurlconnection

我的代码向网站发出POST请求,但响应看起来像加密,有奇怪的字符。当我配置我的应用程序以使用fiddler代理时,响应是有效的。如何让我的应用程序解密此响应?

public class Login {
public Login() throws Exception {
URL url = new URL("https://account.leagueoflegends.com/auth");
HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
conn.setDoInput(true);
conn.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36");
conn.addRequestProperty("Cookie", "xxx");
conn.addRequestProperty("Content-Length", "406");
conn.addRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
conn.addRequestProperty("Accept-Encoding", "gzip,deflate");
conn.addRequestProperty("Connection", "keep-alive");
conn.addRequestProperty("Referer", "xxx");
conn.setDoOutput(true);

OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());

writer.write("xxx");
writer.flush();
String line;
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((line = reader.readLine()) != null) {
  System.out.println(line);
}
writer.close();
reader.close();

}

1 个答案:

答案 0 :(得分:3)

您明确要求压缩流:

conn.addRequestProperty("Accept-Encoding", "gzip,deflate");

删除该行以删除压缩。压缩与加密不同,幸运的是,它不需要您提供密钥。