gpt4 book ai didi

java - ArrayStoreException 使用 apache httpasyncclient 发帖

转载 作者:太空宇宙 更新时间:2023-11-04 11:13:17 24 4
gpt4 key购买 nike

实际上客户端驻留在 tomcat 8080 中,而 REST API 驻留在 9090 中。当移动到更高的环境时,URL 会有所不同。我没有看到使用 httpasyncclient 对 REST API 进行调用。我从 Apache 网站复制了代码 https://hc.apache.org/httpcomponents-asyncclient-dev/examples.html

不确定,即使我收到异常响应,如何使调用成功

CloseableHttpAsyncClient client = HttpAsyncClients.createDefault();
try {
client.start();
JsonObject obj = new JsonObject();
obj.addProperty("username", "username");
obj.addProperty("password", "password");



String serverURL = "http://localhost:9090/project/api";

HttpPost postRequest = new HttpPost(serverURL);
StringEntity params = new StringEntity(obj.toString(), "UTF-8");
params.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "x-www-form-urlencoded"));
postRequest.setEntity(params);

Future<HttpResponse> future = client.execute(postRequest, null);
HttpResponse response = future.get();


} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
} finally {
try {
client.close();
} catch (IOException e) {
e.printStackTrace();
}


}

我没有找到任何有关解决此问题的有用信息。任何帮助都会让我开心

Caused by: java.lang.ArrayStoreException: org.apache.http.impl.cookie.RFC2965VersionAttributeHandler
at org.apache.http.impl.cookie.DefaultCookieSpecProvider.create(DefaultCookieSpecProvider.java:93)
at org.apache.http.client.protocol.RequestAddCookies.process(RequestAddCookies.java:152)
at org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:133)
at org.apache.http.impl.nio.client.MainClientExec.prepareRequest(MainClientExec.java:520)
at org.apache.http.impl.nio.client.MainClientExec.prepare(MainClientExec.java:146)
at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.start(DefaultClientExchangeHandlerImpl.java:124)
at org.apache.http.impl.nio.client.InternalHttpAsyncClient.execute(InternalHttpAsyncClient.java:141)
at org.apache.http.impl.nio.client.CloseableHttpAsyncClient.execute(CloseableHttpAsyncClient.java:74)
at org.apache.http.impl.nio.client.CloseableHttpAsyncClient.execute(CloseableHttpAsyncClient.java:107)
at org.apache.http.impl.nio.client.CloseableHttpAsyncClient.execute(CloseableHttpAsyncClient.java:91)

javadoc 说

Open Declaration java.util.concurrent.ExecutionException Exception thrown when attempting to retrieve the result of a task that aborted by throwing an exception. This exception can be inspected using the getCause() method.

最佳答案

最可能的原因 - httpclient 版本冲突。 F.e.项目依赖项包括 httpclienthttpasyncclienthttpasyncclient 对另一个版本的 httpclient 具有传递依赖性。结果项目依赖项有 2 个不兼容的 httpclient 版本。这里描述了其中一个带有详细解释的案例:https://stackoverflow.com/a/49898063/4651234

关于java - ArrayStoreException 使用 apache httpasyncclient 发帖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45761318/

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