本文介绍了java.io.IOException异常:在连接流意外结束(Android版,jsoup)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我解析有些歌词网站,我有错误从报头。结果
URL,我给它(举例):结果
I am parsing some lyrics site, and i have error from the header.
URL, that i give to it (for example):
http://www.azlyrics.com/lyrics/linkinpark/intheend.html
class GetLyrics extends AsyncTask<String, Void, String> {
protected String doInBackground(String... urls) {
String url = urls[0];
String output;
output = "If you see this, some kind of error has occupied";
try {
Document document = Jsoup.connect(url).post(); //I dont know how it works, its google
document.outputSettings(new Document.OutputSettings().prettyPrint(false));//makes html() preserve linebreaks and spacing
document.select("br").append("\\n");
Elements lyrics = document.select("b + br + br + div"); //Search for lyrics <div> tag, that after <b> and 2 <br> tags
String s = lyrics.html().replaceAll("\\\\n", "\n"); //Google again
output = Jsoup.clean(s, "", Whitelist.none(), new Document.OutputSettings().prettyPrint(false));
output = output.replace("\n\n", "\n");
output = output.substring(4); //Remove first enters
}
catch (HttpStatusException e) {
System.err.println("404 error: " + e);
System.err.println("Check your input data");
output = "An 404 error has occurred, more info:\n" + e + "\nCheck your input data";
Log.d("LyricFinder", e.toString());
}
catch (Exception e) {
System.err.println("Some error: " + e);
output = "An uknown error has occurred\nCheck your internet connection";
Log.d("LyricFinder", e.toString());
}
return output;
}
protected void onPostExecute(String lyrics) {
lyricsOutput.setText(lyrics);
}
}
和日志是:
D/LyricFinder: java.io.IOException: unexpected end of stream on Connection{www.azlyrics.com:80, proxy=DIRECT@ hostAddress=85.17.159.246 cipherSuite=none protocol=http/1.1} (recycle count=0)
在日食控制台项目这code完美的作品(但不这样的AsyncTask:/)结果
我新手,我正与互联网和jsoup第一份工作。
In eclipse console project this code works perfectly (but without this asynctask :/ )
I newbie, and i'm working first with internet and jsoup.
推荐答案
有一件事情,我可以看到的是,您使用的是 POST
请求而不是一个 GET
来获取文档。
One thing that I can see is that you are using a POST
request instead of a GET
to retrieve the document.
只要修改
Document document = Jsoup.connect(url).post();
到
Document document = Jsoup.connect(url).get();
这篇关于java.io.IOException异常:在连接流意外结束(Android版,jsoup)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!