gpt4 book ai didi

java - htmlunit-2.7-java.net.SocketException : Connection reset

转载 作者:太空宇宙 更新时间:2023-11-04 11:18:44 25 4
gpt4 key购买 nike

我正在尝试使用 htmlunit-2.7 库(这是 SoapUI-5.2.1 中可用的默认库)来自动化用户级 token 检索过程(OAuth2 的授权代码授予流程)。但当我尝试通过 htmlunit-2.7 的 WebClient 类连接到 Google Page 时,收到连接重置错误。

下面是我的代码,

我在项目中使用的依赖 Jar 文件,

commons-codec-1.3.jarcommons-httpclient-3.1.jarcommons-io-2.4.jarcommons-lang-2.4.jarcommons-logging-1.1.1.jarhtmlunit-2.7.jarhtmlunit-core-js-2.7.jarsac-1.3.jarxercesImpl-2.9.1.jar

import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;

public class HTMLUnitClass
{

public static void main(String[] args)
{
// TODO Auto-generated method stub


System.out.println("Starting the Script");

try
{
//Webpage Login
WebClient driver = new WebClient();
System.out.println("Instantiating the WebClient");


driver.setJavaScriptEnabled(true);
System.out.println("Enabling the Java Script");
driver.setThrowExceptionOnScriptError(false);
System.out.println("Disabling the Throw Exception on Script Error");


try
{
driver.getPage("https://www.google.com");
System.out.println("Getting the Google Page");

}
catch(Exception e)
{
System.out.println("Exception in the HTML Unit Driver Block: " + e);
}


}
catch (Exception e)
{
System.out.println("Exception in the HTTPClient Block" + e);
}




}

}

我收到以下错误 - 堆栈如下,

Starting the Script
Instantiating the HTMLUnit Driver
Enabling the Java Script
Disabling the Throw Exception on Script Error
Jul 18, 2017 6:34:41 PM org.apache.commons.httpclient.HttpMethodDirector executeWithRetry
INFO: I/O exception (java.net.SocketException) caught when processing request: Connection reset
Jul 18, 2017 6:34:41 PM org.apache.commons.httpclient.HttpMethodDirector executeWithRetry
INFO: Retrying request
Jul 18, 2017 6:34:41 PM org.apache.commons.httpclient.HttpMethodDirector executeWithRetry
INFO: I/O exception (java.net.SocketException) caught when processing request: Connection reset
Jul 18, 2017 6:34:41 PM org.apache.commons.httpclient.HttpMethodDirector executeWithRetry
INFO: Retrying request
Jul 18, 2017 6:34:41 PM org.apache.commons.httpclient.HttpMethodDirector executeWithRetry
INFO: I/O exception (java.net.SocketException) caught when processing request: Connection reset
Jul 18, 2017 6:34:41 PM org.apache.commons.httpclient.HttpMethodDirector executeWithRetry
INFO: Retrying request
Exception in the HTML Unit Driver Block: java.net.SocketException: Connection reset

NOTE-1: Please note that, I cannot go with the latest HtmlUnitDriver Library (Jar), because that will cause version conflicts with the default libraries of the SoapUI-5.2.1 That is the reason for me to stick to the Default Libraries provided in the Installation package of SoapUI-5.2.1 and trying to integrate this solution with the Groovy Script available in one of the Test Steps of the SoapUI.

NOTE-2: I tried using the Apache OAuth Client 2.0 Library as well for automating the Level Token Generation (My Clarification on OAuth Client 2.0 Library)

有人可以阐明如何解决此连接重置问题吗?

最佳答案

我自己也遇到了同样的问题,正确的解决方案是@canpan14在第一条评论中提出的解决方案

我克服此错误的解决方案如下:

WebClient webClient = new WebClient(BEST_SUPPORTED);
webClient.getOptions().setUseInsecureSSL(true); //ignore insecure ssl exception
webClient.getOptions().setSSLClientProtocols(new String[] { "TLSv1.2","TLSv1.1" });

最后一行代码实际上设置要使用的 TLS 类型。为了使您的代码正常工作,首选 TLSv1.2。

关于java - htmlunit-2.7-java.net.SocketException : Connection reset,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45169852/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com