简体   繁体   中英

Server returned HTTP response code 503 for URL

I'm able to access website kissmanga.com yet I can't access it via program. I fixed error 403 that I was getting before that but now I get error 503.

    URL url = new URL("http://kissmanga.com/");
    System.setProperty("http.agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.29 Safari/537.36"); 
    BufferedReader bf = new BufferedReader(new InputStreamReader(url.openStream()));

    String str;
    while((str = bf.readLine()) != null){
        System.out.println(str);
    }


 Error that I get:
Exception in thread "main" java.io.IOException: Server returned HTTP response code: 503 for URL: http://kissmanga.com/
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.URL.openStream(Unknown Source)
at KissManga.main(KissManga.java:10)

Okay this code works with one small annoying problem. I don't get full html but just 2/3 of it.

    HtmlUnitDriver driver = new HtmlUnitDriver();
    driver.get("http://kissmanga.com/");
    Thread.sleep(5000);
    System.out.println(driver.getPageSource());
    driver.quit();

You won't get any data this way, because site checks for Javascript enabled.

You should try tools which can emulate browser behaviour. For example, that's how you can get page source with the help of Selenium Htmlunit Driver :

    HtmlUnitDriver drv = new HtmlUnitDriver(BrowserVersion.FIREFOX_38);
    drv.setJavascriptEnabled(true);
    drv.get("http://kissmanga.com/");
    drv.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    System.out.println(drv.getPageSource());

Error 503 means that server is reachable, but returned an error status code

503 is for "Service Unavailable"

Maybe a problem happened temporarily on server or server rejected your request for some reason

It's because the site appears to use Cloudflare. You can tell when you visit the site and get 'please wait while we check your browser'

503 = HTTP 503 Service Unavailable

This is Cloudflare telling you to hang on while it makes sure you aren't a DDOS.

You will need to code your parser to review the body and either wait out the redirect, or visit it manually yourself.

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