实际上,客户端驻留在tomcat 8080中,REST驻留在9090中。当URL移动到更高的环境时,URL将是不同的。我没有看到使用httpasyncclient调用REST。我从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()方法检查此异常。
发布于 2018-04-18 11:13:19
最可能的原因-- httpclient版本中的冲突。F.e.项目依赖项包括httpclient和httpasyncclient。httpasyncclient对另一个版本的httpclient具有传递依赖关系。因此,项目依赖有两个不兼容的httpclient版本。下面描述了其中一个有详细解释的案例:https://stackoverflow.com/a/49898063/4651234
https://stackoverflow.com/questions/45761318
复制相似问题