HttpGet get = new HttpGet(url); giving exceptions
Asked Answered
P

2

5

I am trying to do a very simple thing which was working a couple of days ago.

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

It is giving the following error

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)

I faced this error earlier using a deprecated client and I changed it to using HTTPClientBuilder. I am not sure why it is giving on HTTPGet. Any help is greatly appreciated.

Palmation answered 3/10, 2014 at 21:54 Comment(4)
what version of HttpClient are you using?Anaplastic
Sorry, My bad. I should have mentioned that in my question. I am using 4.3.Palmation
this does not make sense. 'default' cookie policy was introduced in version 4.4Anaplastic
I would love to have a followup on this. We're hitting the exact same problem: our code suddenly stopped working, and we get the exact same exception and callstack. I don't know what changed since it last worked. Maybe another package has been updated? Did you end up finding what the cause of the problem was?Eslinger
B
9

It's a bug from apache httpclient, version 4.4 beta 1 has this bug, but version 4.3.6 works fine for me.

If you are using maven, use following in pom:

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

And don't update it to 4.4 before they fix this bug.

Bode answered 30/12, 2014 at 3:58 Comment(3)
have you got a reference to the bug? can we upvote it?Blindstory
@Blindstory I didn't research the bug any more after I fix the issue by changing the version. I feel issues like this don't worth much time.Bode
Also breaks Sardine 5.0Alvie
H
-1

try this code

http.get(Uri.parse('https://jsonplaceholder.typicode.com/albums/1')); }

Hua answered 19/10, 2021 at 11:58 Comment(1)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewBenge

© 2022 - 2025 — McMap. All rights reserved.