我收到以下錯誤,當我嘗試使用HttpClient的做一做:HttpClient的GET錯誤 - java.lang.ClassCastException:[B不能轉換爲java.lang.String
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)
我的Referer是:https://portaldecustas.tjsp.jus.br/portaltjsp/login.jsp
我的目標是: https://portaldecustas.tjsp.jus.br/portaltjsp/
我GET配置: [expectContinueEnabled =虛假,代理= NULL,將localAddress = NULL,cookieSpe c = null,redirectsEnabled = true,relativeRedirectsAllowed = true,maxRedirects = 50,circularRedirectsAllowed = false,authenticationEnabled = true,targetPreferredAuthSchemes = null,proxyPreferredAuthSchemes = null,connectionRequestTimeout = 1000,connectTimeout = 60000,socketTimeout = 60000,contentCompressionEnabled = true]
(我已搜查這個錯誤,但我沒有找到一個soluction對於這種特殊情況下)
它是代碼:
HttpGet get = newGetMethod(getTarget(), getTimeoutHandler());
HtmlNode htmlNode = requestHtml(get);
...當newGetMethod這是一個methos從我公司的框架:
/**
* 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;
}
問題不清楚! B類的定義是什麼?你也可以把整個堆棧跟蹤? – nagendra547
是的,我發送整個堆棧跟蹤... –
它與此類似:https://stackoverflow.com/questions/14022602/java-lang-classcastexception-b-cannot-be-cast-to-java-lang-string 但在我的情況下,它有點不同...真的很難發現 –