Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Server returned HTTP response code: 523 for URL: http

I want to crawl a webpage, the request type is post,but I get an error: java.io.IOException: Server returned HTTP response code: 523 for URL: http://

public static String readContentFromPost(String urlStr, String content) {
    URL url = null;
    HttpURLConnection con = null;
    StringBuffer sb = new StringBuffer();

    try {
        url = new URL(urlStr);
        con = (HttpURLConnection) url.openConnection();
        con.setDoOutput(true);
        con.setDoInput(true);
        con.setRequestMethod("POST");
        con.setUseCaches(false);
        con.setInstanceFollowRedirects(true);
        con.setRequestProperty("Content-Type", "text/html;charset=utf-8");
        con.connect();

        DataOutputStream out = new DataOutputStream(con.getOutputStream());
        out.writeBytes(content);

        out.flush();
        out.close();

        BufferedReader br = new BufferedReader(new InputStreamReader(
                con.getInputStream()));

        String line;
        while ((line = br.readLine()) != null) {
            sb.append(line);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return sb.toString();
}
like image 467
free斩 Avatar asked Mar 02 '26 23:03

free斩


1 Answers

The error 523 doesn't have any standard meaning: http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml

So it's a propietary error of the server you're trying to crawl... Try to contact the web administrator to know what it means.

523 doesn't mean Unreachable origin... it only means that in Cloudflare: https://support.cloudflare.com/hc/en-us/articles/200171946-Error-523-Origin-is-unreachable

Try your code with a well-know server like Google or Wikipedia in order to know if it works fine.

like image 144
Eduardo Yáñez Parareda Avatar answered Mar 05 '26 13:03

Eduardo Yáñez Parareda