1

我在一个android应用程序中使用jsoup来获取一个url,我得到了这个错误并且搜索了很多但找不到答案,你能给我一些建议吗?谢谢!我在Android 2.1模拟器中测试,代码如下:

Document doc;
String firstHash = "";
try {
    doc = Jsoup.connect(mURL)
        .userAgent("Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0")
        .timeout(10000).followRedirects(true).execute().parse();
        firstHash = doc.body().text();
} catch (Exception e) {
        e.printStackTrace();
}

堆栈跟踪如下:

10-20 08:42:37.586: W/System.err(223): org.jsoup.HttpStatusException: HTTP error fetching URL. Status=-1, URL=http://www.shooter.cn/files/file3.php?hash=duei7chy7gj59fjew73hdwh213f&fileid=244789
10-20 08:42:37.606: W/System.err(223):  at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:435)
10-20 08:42:37.606: W/System.err(223):  at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:410)
10-20 08:42:37.606: W/System.err(223):  at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:164)
4

1 回答 1

0

使用ignoreHttpErrors(true),一定能解决你的问题

Document doc3 = null;
    try {
        doc3 = Jsoup.connect(url).userAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0")
                .referrer("http://www.google.com").ignoreHttpErrors(true).get();

    } catch (NullPointerException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
于 2015-12-08T16:42:32.177 回答