java.net.SocketException:使用Jsoup重置连接

问题描述

我需要使用jsoup库连接https://www.casasbahia.com.br/,正在接收java.net.socketException:连接重置异常

这是我的代码

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

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

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)