HttpClient GET Error语言 - java.lang.ClassCastException: [B 不能强制



当我尝试使用HttpClient执行 DO 时,我收到以下错误:

java.lang.ClassCastException: [B cannot be cast to java.lang.String
at org.apache.http.conn.ssl.DefaultHostnameVerifier.getSubjectAltNames(DefaultHostnameVerifier.java:309)
at org.apache.http.conn.ssl.DefaultHostnameVerifier.verify(DefaultHostnameVerifier.java:112)
at org.apache.http.conn.ssl.DefaultHostnameVerifier.verify(DefaultHostnameVerifier.java:99)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.verifyHostname(SSLConnectionSocketFactory.java:463)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:397)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:355)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
at br.com.serasa.captacao.framework.web.http.HttpHelper.executeRequestForAnyResponse(HttpHelper.java:735)
at br.com.serasa.captacao.framework.web.http.HttpHelper.executeHtmlRequest(HttpHelper.java:463)
at br.com.serasa.captacao.framework.web.http.HttpHelper.executeHtmlRequest(HttpHelper.java:448)
at br.com.serasa.captacao.framework.web.page.Page.requestHtml(Page.java:98)
at br.com.fiveware.dare.sp.emissao.guias.captador.page.DareSpPage.abrirPaginaInicial(DareSpPage.java:37)
at br.com.fiveware.dare.sp.emissao.guias.captador.CaptadorDareSP.abrirPaginaInicial(CaptadorDareSP.java:30)
at br.com.fiveware.dare.sp.emissao.guias.captador.page.DareSpPageTest.abrirPaginaInicialTest(DareSpPageTest.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

我的推荐人是:https://portaldecustas.tjsp.jus.br/portaltjsp/login.jsp

我的目标是: https://portaldecustas.tjsp.jus.br/portaltjsp/

我的 GET 配置: [expectContinueEnabled=false, proxy=null, localAddress=null, cookieSpec=null, redirectsEnabled=true, relativeRedirectsAllowed=true, maxRedirects=50, circularRedirectsAllowed=false, authenticationEnabled=true, targetPreferredAuthSchemes=null, proxyPreferredAuthSchemes=null, connectionRequestTimeout=1000, connectTimeout=60000, socketTimeout=60000, contentCompressionEnabled=true]

(我已经搜索了这个错误,但我没有找到这个特定案例的解决方案(

它的代码:

HttpGet get = newGetMethod(getTarget(), getTimeoutHandler());
HtmlNode htmlNode = requestHtml(get);

。当newGetMethod是我公司框架中的一种方法:

/**
* Cria um get
* 
* @param target Endere?o acessado
* @param timeoutHandler Controla o timeout
* @return Get
* @throws HarvestException Quando ocorre um erro com o tempo a ser usado
*/
public static HttpGet newGetMethod(URI target, TimeoutHandler timeoutHandler) throws HarvestException {
HttpGet method = newGetMethod(target, timeoutHandler.calculate());
method.getParams().setParameter(TIMEOUT_HANDLER_PARAM, timeoutHandler);
return method;
}

这是我的.pom文件中的Http客户端版本

我用这个解决了:

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.3</version>
</dependency>

如果您使用的是 httpclient 库的4.5.35.0 Alpha1版,这是由于错误 - https://issues.apache.org/jira/browse/HTTPCLIENT-1836

更新到4.5.4/5.0 Alpha2或更高版本。

相关内容

  • 没有找到相关文章