Search code examples
javahttp-status-code-500

How to download the content of the page despite the Error 500?


I want to download the content of the page: https://www.hafen-hamburg.de/en/vessels/klein-erna/. In my code and DevTools I can see that I'm getting a 500 error:

Statuscode 500

but I can also clearly see in the browser that the page has been loaded. How can I download the content of the page despite this error?

My code:

    String pageUrl = "https://www.hafen-hamburg.de/en/vessels/klein-erna/";
    URL url = new URL(pageUrl);
    String content = IOUtils.toString(url, StandardCharsets.UTF_8);

Solution

  • thanks for your comment (@egeorge) I used the HttpClient library and got exactly what I wanted.

    Code:

        String pageUrl = "https://www.hafen-hamburg.de/en/vessels/klein-erna/";
        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder().uri(URI.create(pageUrl)).build();
        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());