Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9119399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:23:13+00:00 2026-06-17T05:23:13+00:00

I am using apache HttpClient. While debugging something, I found I am getting error

  • 0

I am using apache HttpClient. While debugging something, I found I am getting error when I execute the same HTTPS HEAD request for the second time using the same connection (connection kept alive). The host is https://dongshengcn.iriscouch.com. I am not sure where is wrong, is the server? is it a HttpClient bug? I tend to think this is a HttpClient bug somewhere. Anyways, I am wondering if someone can point me to the right direction. Here is the code and logging info:

import org.apache.http.HttpHost;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;
import org.junit.Test;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * User: dongsheng
 * Date: 1/10/13
 * Time: 4:10 PM
 * To change this template use File | Settings | File Templates.
 */
public class HttpClientTest {

    private int connectionTimeout = 1000;
    private int socketTimeout = 10000;
    private String host = "dongshengcn.iriscouch.com";
//    private String host = "dongshengcn.cloudant.com";
    private int port = 443;
    boolean useExpectContinue = true;

    public DefaultHttpClient configureClient() {
        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setUseExpectContinue(params, useExpectContinue);
        HttpConnectionParams
                .setConnectionTimeout(params, connectionTimeout);
        HttpConnectionParams.setSoTimeout(params, socketTimeout);
        HttpConnectionParams.setTcpNoDelay(params, Boolean.TRUE);

        String protocol = "https";
        params.setParameter(ClientPNames.DEFAULT_HOST, new HttpHost(host,
                port, protocol));
        DefaultHttpClient client = new DefaultHttpClient(params);

        return client;
    }

    @Test
    public void test_dafault_http_client() throws IOException {
        String uri = "/ektorp-test/";
        DefaultHttpClient client = configureClient();

        org.apache.http.HttpResponse rsp = client.execute(new HttpHead(uri));
        System.out.println(rsp.toString());

        try {
            org.apache.http.HttpResponse rsp2 = client.execute(new HttpHead(uri));
            System.out.println(rsp.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}



Running HttpClientTest
2013/01/11 10:12:05:288 EST [DEBUG] BasicClientConnectionManager - Get connection for route {s}->https://dongshengcn.iriscouch.com:443
2013/01/11 10:12:06:065 EST [DEBUG] DefaultClientConnectionOperator - Connecting to dongshengcn.iriscouch.com:443
2013/01/11 10:12:07:201 EST [DEBUG] RequestAddCookies - CookieSpec selected: best-match
2013/01/11 10:12:07:223 EST [DEBUG] RequestAuthCache - Auth cache not set in the context
2013/01/11 10:12:07:223 EST [DEBUG] RequestTargetAuthentication - Target auth state: UNCHALLENGED
2013/01/11 10:12:07:224 EST [DEBUG] RequestProxyAuthentication - Proxy auth state: UNCHALLENGED
2013/01/11 10:12:07:224 EST [DEBUG] DefaultHttpClient - Attempt 1 to execute request
2013/01/11 10:12:07:224 EST [DEBUG] DefaultClientConnection - Sending request: HEAD /ektorp-test/ HTTP/1.1
2013/01/11 10:12:07:226 EST [DEBUG] headers - >> HEAD /ektorp-test/ HTTP/1.1
2013/01/11 10:12:07:226 EST [DEBUG] headers - >> Host: dongshengcn.iriscouch.com:443
2013/01/11 10:12:07:226 EST [DEBUG] headers - >> Connection: Keep-Alive
2013/01/11 10:12:07:303 EST [DEBUG] DefaultClientConnection - Receiving response: HTTP/1.1 404 Host not found
2013/01/11 10:12:07:304 EST [DEBUG] headers - << HTTP/1.1 404 Host not found
2013/01/11 10:12:07:304 EST [DEBUG] headers - << Content-Length: 14
2013/01/11 10:12:07:307 EST [DEBUG] DefaultHttpClient - Connection can be kept alive indefinitely
2013/01/11 10:12:07:309 EST [DEBUG] BasicClientConnectionManager - Releasing connection org.apache.http.impl.conn.ManagedClientConnectionImpl@21cc5069
2013/01/11 10:12:07:309 EST [DEBUG] BasicClientConnectionManager - Connection can be kept alive indefinitely
HTTP/1.1 404 Host not found [Content-Length: 14]
2013/01/11 10:12:07:309 EST [DEBUG] BasicClientConnectionManager - Get connection for route {s}->https://dongshengcn.iriscouch.com:443
2013/01/11 10:12:07:310 EST [DEBUG] DefaultHttpClient - Stale connection check
2013/01/11 10:12:07:311 EST [DEBUG] RequestAddCookies - CookieSpec selected: best-match
2013/01/11 10:12:07:311 EST [DEBUG] RequestAuthCache - Auth cache not set in the context
2013/01/11 10:12:07:311 EST [DEBUG] RequestTargetAuthentication - Target auth state: UNCHALLENGED
2013/01/11 10:12:07:311 EST [DEBUG] RequestProxyAuthentication - Proxy auth state: UNCHALLENGED
2013/01/11 10:12:07:311 EST [DEBUG] DefaultHttpClient - Attempt 1 to execute request
2013/01/11 10:12:07:311 EST [DEBUG] DefaultClientConnection - Sending request: HEAD /ektorp-test/ HTTP/1.1
2013/01/11 10:12:07:311 EST [DEBUG] headers - >> HEAD /ektorp-test/ HTTP/1.1
2013/01/11 10:12:07:311 EST [DEBUG] headers - >> Host: dongshengcn.iriscouch.com:443
2013/01/11 10:12:07:311 EST [DEBUG] headers - >> Connection: Keep-Alive
2013/01/11 10:12:07:314 EST [DEBUG] DefaultHttpResponseParser - Garbage in response: Host not found
2013/01/11 10:12:07:314 EST [DEBUG] DefaultClientConnection - Connection 0.0.0.0:62168<->173.192.57.98:443 closed
2013/01/11 10:12:07:315 EST [DEBUG] DefaultClientConnection - Connection 0.0.0.0:62168<->173.192.57.98:443 shut down
2013/01/11 10:12:07:315 EST [DEBUG] BasicClientConnectionManager - Releasing connection org.apache.http.impl.conn.ManagedClientConnectionImpl@67c7980c
2013/01/11 10:12:07:315 EST [DEBUG] BasicClientConnectionManager - Connection can be kept alive for 9223372036854775807 MILLISECONDS
org.apache.http.client.ClientProtocolException
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:909)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:784)
    at HttpClientTest.test_dafault_http_client(HttpClientTest.java:69)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
    at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
    at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
Caused by: org.apache.http.ProtocolException: The server failed to respond with a valid HTTP response
    at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:103)
    at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:62)
    at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:254)
    at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:289)
    at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:252)
    at org.apache.http.impl.conn.ManagedClientConnectionImpl.receiveResponseHeader(ManagedClientConnectionImpl.java:191)
    at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:300)
    at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:127)
    at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:712)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:517)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
    ... 32 more
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.411 sec

If I change the host to a difference one like dongshengcn.cloudant.com:443, and it works as expected.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:23:15+00:00Added an answer on June 17, 2026 at 5:23 am

    Quite likely the server does not correctly handle HEAD requests and sends a response body in response to the first request in violation of the HTTP specification corrupting connection state and rendering it non-reusable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using apache's common httpclient library. Is it possible to make HTTP request
I am using the Apache HttpClient (4.1) included in Android to execute a HttpPut.
While using the Rotten Tomatoes API I am getting the following error: org.json.JSONException: Value
I'm using Apache's HttpClient (for Java) load a Url that is getting redirected by
trying to access http://forum.worldoftanks.eu/index.php?app=members using apache HttpClient but keep getting 403. Can anyone help
I am having a strange problem while using Apache HttpClient in an Android app.
While issuing a GET request using Apache HTTP Client v4, how do I obtain
I'm using Apache HttpClient 3.x for contacting a Big IP that will then redirect
I am using Apache HTTPClient 4 to connect to twitter's streaming api with default
I'm trying to retrieve this page using Apache HttpClient: http://quick-dish.tablespoon.com/ Unfortunately, when I try

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.