HttpGet get = new HttpGet(url);给出例外

时间:2014-10-03 21:54:17

标签: java http apache-httpclient-4.x http-get

我正在尝试做一个非常简单的事情,这是几天前工作的。

CloseableHttpClient client = HttpClientBuilder.create().build();
            HttpGet get = new HttpGet(url);
            HttpResponse response = client.execute(get);

出现以下错误

Caused by:
            java.lang.IllegalStateException: Unsupported cookie spec: default
                at org.apache.http.cookie.CookieSpecRegistry.getCookieSpec(CookieSpecRegistry.java:110)
                at org.apache.http.cookie.CookieSpecRegistry$1.create(CookieSpecRegistry.java:163)
                at org.apache.http.client.protocol.RequestAddCookies.process(RequestAddCookies.java:157)
                at org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:132)
                at org.apache.http.protocol.HttpRequestExecutor.preProcess(HttpRequestExecutor.java:166)
                at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:485)
                at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:878)
                at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:84)
                at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:109)
                at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)

我之前使用已弃用的客户端遇到此错误,并将其更改为使用HTTPClientBuilder。我不确定为什么它会给HTTPGet。 非常感谢任何帮助。

1 个答案:

答案 0 :(得分:7)

来自apache httpclient的错误,版本4.4 beta 1有这个错误,但版本4.3.6对我来说很好。

如果您使用的是maven,请在pom中使用以下内容:

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

并且不会在修复此错误之前将其更新为4.4。