Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpGet get = new HttpGet(url); giving exceptions

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.

like image 781
shaun Avatar asked Oct 03 '14 21:10

shaun


1 Answers

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.

like image 103
user218867 Avatar answered Oct 23 '22 09:10

user218867