0

I need to connect https://www.casasbahia.com.br/ using jsoup library, Am recieving java.net.SocketException: Connection reset exception

Here is my code

=============================================================================

    public static String webServiceCall(String hostUrl, Map<String, String> header, String payload, Method method) {
    int retries = 1;
    String htmlContent = "";
    Response responses = null;
    do {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            LoggerUtil.severe(logger, e.getMessage());
        }
        try {
            Connection conn = Jsoup.connect(hostUrl).header("Accept-Encoding", "gzip, deflate");
            if (!(header == null || header.isEmpty())) {
                for (Object key : header.keySet()) {
                    conn.header((String) key, header.get(key));
                }
            }
            if (!Strings.isNullOrEmpty(payload)) {
                conn.requestBody(payload);
            }
            if (method == null) {
                method = Method.GET;
            }
            conn.ignoreContentType(true).followRedirects(true).maxBodySize(0).timeout(0)
                    .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 "
                            + "(KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36")
                    .method(method);
            responses = conn.execute();
        } catch (IOException e) {
            LoggerUtil.severe(logger, e.getMessage());
        }
        retries++;
    } while ((responses == null || responses.statusCode() != SUCCESS_HTTP_STATUS) && retries <= TOTAL_RETRY);

    if (responses != null && responses.statusCode() == SUCCESS_HTTP_STATUS) {
        htmlContent = responses.body();
    }
    return htmlContent;
}
Code007
  • 1
  • 3
  • You know, I have scraped hundreds and hundreds of pages. On this particular **`URL`**, I am encountering something I have not encountered before. I am able to view the **`URL`** on one of my browsers (but not all of them)... However, whenever I attempt to do something as simple as "grab the `HTML`" (and then save it to a `java.lang.String`) - ***the code I have just locks on the `URL`, and doesn't return anything...*** I have tried multiple invokations to get Java to connect to this web-site, but ***all of them failed.*** – Y2020-09 Oct 04 '20 at 01:10
  • 1
    Does this answer your question? [java.net.SocketException: Connection reset](https://stackoverflow.com/questions/62929/java-net-socketexception-connection-reset) – corashina Oct 04 '20 at 09:22
  • @corashina No .. – Code007 Oct 05 '20 at 05:44

0 Answers0