1
URL url = new URL("http://google.com");
URLConnection connection = url.openConnection();
connection.connect();
System.out.println("conncetion successful.");
String contentType = connection.getContentType();
System.out.println(contentType);
contentType为“text/html; charset = EUC-KR”。 (在其他语言环境中可能有所不同),并且文档encdoing与contentType中的一个相同。但是,当我使用web brwoser(IE,Firefox,Opera等)访问相同的URL(“http://google.com”)时,它说这是一个UTF-8编码页面。 (和文件编码实际上是UTF-8。)指定URLConnection响应的文档编码
我想获得UTF-8编码的URLConnection,但似乎没有API。 我该如何做到这一点?