I write following code:
public static void main(String args[]) throws IOException {
URL url = new URL("http://stackoverflow.com/");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
System.out.print(conn.getResponseMessage());
}
Since Java uses by default Java Logging, add the following code:
static {
ConsoleHandler handler = new ConsoleHandler();
handler.setLevel(Level.ALL);
Logger log = LogManager.getLogManager().getLogger("");
log.addHandler(handler);
log.setLevel(Level.ALL);
}
//2. simple header informations:
conn.getHeaderFields().toString(); //response headers
conn.getResponseCode();//response http code
conn.getRequestProperties().toString();//request headers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With