2013-10-20 39 views
1

我在一個android應用程序中使用jsoup來grub一個url,我得到了這個錯誤,並且搜索了很多但找不到答案,你能給我一些建議嗎?謝謝!我測試了在Android 2.1的模擬器,代碼爲波紋管:org.jsoup.HttpStatusException錯誤

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) 

回答

0

使用ignoreHttpErrors(真),肯定會解決你的問題

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(); 
    }