here's a minimal example of what I try to do :
public static String fetch () {
// get a connection to the website
HttpURLConnection connection = (HttpURLConnection)(new URL("http://example.com?param=ok").openConnection());
// configure the connection
connection.setRequestMethod("GET");
connection.setInstanceFollowRedirects(false);
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
// send the request
DataOutputStream ostream = new DataOutputStream(connection.getOutputStream());
ostream.flush();
ostream.close();
// receives the response
InputStream istream = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(istream));
StringBuffer response = new StringBuffer();
String line;
while ((line = reader.readLine()) != null) {
response.append(line);
response.append('\r');
}
reader.close();
return response.toString();
}
To reach "http://example.com", the server sends a redirection first and HttpURLConnection automatically uses this redirection, then displays the response of this final dead-end page. I want to get the byte-code of this intermediary response. To do so, I tried to use the method setInstanceFollowRedirects and set to false (see the code). It seems to work since there is no output anymore but this is why I post here because there is no output anymore fuuuu
Does one have a fricking clue of why nothing is displayed when I try to output the return response.toString();
?