1

My code makes POST request to a website, but the response looks like encrypted, with weird characters. When i configure my app to use fiddler proxy, the response is valid. How can i make my app decrypt this response?

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();

}

Krystian
  • 13
  • 1
  • 3
  • A belated welcome to SO, Krystian. Don't forget to add some sample input from the stream next time Krystian, preferably in hex if the bytes cannot be easily printed as characters. Others, close because the question is unclear? Really? – Maarten Bodewes Nov 19 '14 at 08:32

1 Answers1

3

You are explicitly requesting a zipped stream:

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

Remove that line to remove the compression. Compression is different from encryption fortunately, it doesn't require you to supply a key.

Maarten Bodewes
  • 90,524
  • 13
  • 150
  • 263