java.nio.charset.IllegalCharsetNameException: 'ISO-8859-1'

旧时模样 提交于 2019-12-23 04:18:07

问题


Jsoup.connect("http://www.design.cmu.edu/community.php?s=3").get();

Could someone please show me why the code gave me the error:

java.nio.charset.IllegalCharsetNameException: 'ISO-8859-1'

回答1:


The problem is in the target page. It is not well-formed at all.

When parsing the page, JSoup tries to fix the page and for one thing, parses the content type to "text/html; charset='iso-8859-1'"(with the single quotes included).

It then passes this string(with the single quotes) and uses it to get the charset:

Charset.forName("'ISO-8859-1'");

which fails.

The problem is in the target page. Maybe you can use this alternative instead, which doesn't parse the charset from the page, because you explicitly pass it along:

String url = "http://www.design.cmu.edu/community.php?s=3";
Document document = Jsoup.parse(new URL(url).openStream(), "ISO-8859-1", url);


来源:https://stackoverflow.com/questions/12225494/java-nio-charset-illegalcharsetnameexception-iso-8859-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!