我写下面的代码:
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());
}
答案 0 :(得分:3)
由于Java默认使用Java Logging,因此请添加以下代码:
static {
ConsoleHandler handler = new ConsoleHandler();
handler.setLevel(Level.ALL);
Logger log = LogManager.getLogManager().getLogger("");
log.addHandler(handler);
log.setLevel(Level.ALL);
}
答案 1 :(得分:0)
// 2。简单的标题信息:
conn.getHeaderFields().toString(); //response headers
conn.getResponseCode();//response http code
conn.getRequestProperties().toString();//request headers