为什么 String key = DigestUtils.md5Hex(conn.getInputStream()); 使用后,后面就不能用了,难道必须要两次 HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 吗?
@Test
public void test() {
try {
URL url = new URL("http://www.baidu.com/img/270_fbe71c0815a61fd81c5b89573a002f38.png");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");// 声明请求方式
conn.setConnectTimeout(6 * 1000);// 设置连接超时
conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon;)");
conn.setRequestProperty("Accept-Encoding", "identity");
if (conn.getResponseCode() == 200) {
String key = DigestUtils.md5Hex(conn.getInputStream());
System.out.println(key);
BufferedImage img = ImageIO.read(conn.getInputStream());
int width = img.getWidth();
int height = img.getHeight();
System.out.println(width);
System.out.println(height);
}
} catch (Exception e) {
e.printStackTrace();
}
}
慕雪6442864
慕码人8056858
相关分类