实际上客户端位于tomcat 8080& REST API驻留在9090.当URL移动到更高的环境时,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)
javadocs说
打开声明java.util.concurrent.ExecutionException异常 尝试检索中止任务的结果时抛出 通过抛出异常。可以使用以下方法检查此异常 getCause()方法。
答案 0 :(得分:0)
最可能的原因 - httpclient
版本中的冲突。 F.E.项目依赖项包括httpclient
和httpasyncclient
。 httpasyncclient
对另一版httpclient
具有传递依赖性。结果项目依赖项有2个不兼容的httpclient
版本。其中一个具有详细解释的案例在此处描述:https://stackoverflow.com/a/49898063/4651234