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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.