微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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 举报,一经查实,本站将立刻删除。