NoSuchFieldError:使用HttpClient进行实例

时间:2016-06-30 17:10:36

标签: java maven header http-post apache-httpclient-4.x

我正在使用HttpClient在REST API上发布请求,如下所示

    HttpClient client = HttpClientBuilder.create().build();
    HttpPost post = new HttpPost(url);
    post.setHeader("Content-Type","application/json");
    post.addHeader("Authorization", "Bearer " +authToken);
    JSONObject json = new JSONObject();
    json.put("image_url", ");
    json.put("job_fqn","");
    JSONArray routesJsonArray = new JSONArray();
    routesJsonArray.put(0, "");
    json.put("routes",routesJsonArray);
    StringEntity params = new StringEntity(json.toString());
    post.setEntity(params);
    HttpResponse  response = client.execute(post);
    client.getConnectionManager().shutdown();

这给出了

java.lang.NoSuchFieldError: INSTANCE
当时创建HTPClient对象时出现

错误

我的pom文件包含

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.4.1</version>
    </dependency>

我解决的依赖项包含

 httpclient:4.4.1
 httpcore 4.4.1

由于它的版本相同,我认为它不应该导致版本冲突。还有其他我错过的吗?

这是堆栈跟踪

[[ERROR] [06/30/2016 13:26:27.762] [-akka.actor.default-dispatcher-7] [ActorSystem(deployer)] Uncaught error from thread [-akka.actor.default-dispatcher-7] shutting down JVM since 'akka.jvm-exit-on-fatal-error' is enabled
java.lang.NoSuchFieldError: INSTANCE
    at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:52)
    at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:56)
    at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<clinit>(DefaultHttpRequestWriterFactory.java:46)
    at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:72)
    at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:84)
    at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<clinit>(ManagedHttpClientConnectionFactory.java:59)
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$InternalConnectionFactory.<init>(PoolingHttpClientConnectionManager.java:493)
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:149)
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:138)
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:114)
    at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:726)

当我尝试访问HttpClientBuilderClass的第726行时,我没有看到构建器方法?该课程在第431行结束!

0 个答案:

没有答案