使用Jsoup访问HTML但收到错误代码503 [英] Using Jsoup to access HTML but receives error code 503

查看:1525
本文介绍了使用Jsoup访问HTML但收到错误代码503的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图访问 KissAnime ,但是,我一直收到此错误:

I have been trying to access KissAnime however, i kept receiving this error:


org.jsoup.HttpStatusException:获取URL的HTTP错误。状态= 503

org.jsoup.HttpStatusException: HTTP error fetching URL. Status=503

当我尝试另一个网址时,例如。 https://www.google.com/ ,效果很好。

When i tried another URL eg. https://www.google.com/, it works perfectly.

这是我的asynctask代码:

This is my asynctask code:

 @Override
    protected Void doInBackground(Void... params) {
        try {
            // Connect to the web site
            Document document = Jsoup.connect("https://kissanime.to/AnimeList/")
                    .ignoreContentType(true)
                    .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1")
                    .referrer("http://www.google.com")
                    .timeout(12000)
                    .followRedirects(true)
                    .get();
            // Get the html document title
            title = document.title();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

任何想法如何解决这个问题?

Any idea how to solve this problem?

推荐答案

为了摆脱503,下面的代码会很有用。

To get rid of 503, below code would be useful.

   public static void main(String[] args) throws IOException {
        //This will get you out of Http 503
        Document document = Jsoup.connect("https://kissanime.to/AnimeList/")
                .userAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:49.0) Gecko/20100101 Firefox/49.0").ignoreHttpErrors(true).followRedirects(true).timeout(100000).ignoreContentType(true).get();
        System.out.println(document.body());
}

这篇关于使用Jsoup访问HTML但收到错误代码503的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆