java - ArrayStoreException 使用 apache httpasyncclient 发帖

标签 java http-post apache-httpasyncclient

实际上客户端驻留在 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/

相关文章:

java - 是否可以在父类(super class)对象上调用子类的方法?

java - 将 1、15、30 或 45 分钟添加到 currentTimeMillis()

php - 为什么POST请求返回404

java - GWT:如何使用 JSON 发送 POST 跨域请求

java - RequestConfig 和 IOReactorConfig 超时设置的区别?

java - 忽略 AsyncClientHttp2Multiplexing 中的自签名证书

java - 在 Android 中使用定时器进行短信调度

java - 在 Java 中实现 Creator 类和类本身设计的正确方法是什么?

ios http POST(数据和图像): Image not getting posted

java - org.apache.http.ConnectionClosedException : Connection closed - PoolingNHttpClientConnectionManager