[英]JSoup triggers “java.nio.charset.IllegalCharsetNameException: iso-8859-1”
I've been working on a project for almost five months and until now I didnt see any failure like: "java.nio.charset.IllegalCharsetNameException: iso-8859-1" during a JSoup connect try. 我已经在一个项目上工作了将近五个月,到目前为止,在JSoup连接尝试期间,我没有看到任何类似“ java.nio.charset.IllegalCharsetNameException:iso-8859-1”的故障。 I don't know if that is just coincidence at all but what is most weird is when it triggers the failure inside the try, the catch is never executed. 我根本不知道这是否只是巧合,但是最奇怪的是,当它触发try内的失败时,从未执行过catch。 I saw this other topic java.nio.charset.IllegalCharsetNameException: iso-8859-1 here on SO, but I couldnt really understand how it would feet on my code because I'm not using a parser. 我在SO上看到了另一个主题java.nio.charset.IllegalCharsetNameException:iso-8859-1 ,但由于无法使用解析器,我无法真正理解它对我的代码的影响。
Code: 码:
private void nodesConnection(String nodeRequest, boolean automaticQuery){
try{
CONNECTED_NODE = nodeRequest;
JSOUP_CONNECTION = Jsoup.connect(CONNECTED_NODE)
.userAgent("Mozilla/5.0 (compatible; MSIE 10.6; Windows NT 6.1; Trident/5.0; InfoPath.2; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727) 3gpp-gba UNTRUSTED/1.0")
.cookie("auth", "token")
.timeout(5000)
.get();
} catch(IOException e){
System.out.println("This is on Node Request " + e.getMessage());
}
}
Failure print: 失败打印:
Exception in thread "Query Thread" java.nio.charset.IllegalCharsetNameException: iso-8859-1"
at java.nio.charset.Charset.checkName(Unknown Source)
at java.nio.charset.Charset.lookup2(Unknown Source)
at java.nio.charset.Charset.lookup(Unknown Source)
at java.nio.charset.Charset.forName(Unknown Source)
at org.jsoup.helper.DataUtil.parseByteData(DataUtil.java:87)
at org.jsoup.helper.HttpConnection$Response.parse(HttpConnection.java:498)
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:154)
at com.sh.st.request.http.NodeRequests.nodesConnection(NodeRequests.java:60)
at com.sh.st.request.http.NodeRequests.<init>(NodeRequests.java:42)
at com.sh.st.request.http.*.listQueryLinks(*.java:254)
at com.sh.st.request.http.QueryBaseBuilder.<init>(QueryBaseBuilder.java:44)
at com.sh.st.request.tool.SearchRequest.run(SearchRequest.java:100)
at java.lang.Thread.run(Unknown Source)
Does anyone knows whats a possible solution to avoid this exception or could explain what might be wrong? 有谁知道有什么可能的方法来避免这种异常,或者可以解释什么是错的?
What do you mean by "I'm not using a parser."? “我不使用解析器”是什么意思? Jsoup is a parser. Jsoup是一个解析器。 If what you meant was that you don't use parse() method, then that doesn't mean that get() doesn't behave the same as parse as far as Charset is concerned. 如果您的意思是您不使用parse()方法,那么这并不意味着就Charset而言,get()的行为与解析不一样。
From the documentation 从文档中
Document - get()
Execute the request as a GET, and parse the result.
Try this 尝试这个
Connection.Response cr = Jsoup.connect(THE_URL)
.userAgent("Mozilla/5.0 (compatible; MSIE 10.6; Windows NT 6.1; Trident/5.0; InfoPath.2; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727) 3gpp-gba UNTRUSTED/1.0")
.cookie("auth", "token")
.timeout(5000)
.execute();
Document d = Jsoup.parse(cr.body(), "ISO-8859-1");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.