简体   繁体   中英

Using Jsoup to access HTML but receives error code 503

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

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

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

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM