title: Apache HttpComponents: org.apache.http.client.ClientProtocolException
body: <p>So I use apache HttpComponents to handle http request in java.
  Now I want to reuse the <code>DefaultHttpClient</code>, what should be possible accoarding to this example: <a href="http://wiki.apache.org/HttpComponents/QuickStart" rel="nofollow">http://wiki.apache.org/HttpComponents/QuickStart</a>. The example itselfs give a ssl error so I modefied and simplefied it a bit. Now I always get a <code>org.apache.http.client.ClientProtocolException</code></p>
  
  <p>Here is my example program, basicly I just request 2 webpages using the same <code>DefaultHttpClient</code>.</p>
  
  <pre><code>import java.io.ByteArrayOutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  
  import org.apache.http.HttpEntity;
  import org.apache.http.HttpResponse;
  import org.apache.http.client.methods.HttpGet;
  import org.apache.http.impl.client.DefaultHttpClient;
  
  
  public class ClientFormLogin {
  
      public static void main(String[] args) throws Exception {
  
          DefaultHttpClient httpclient = new DefaultHttpClient();
  
          //Handle first request.
          HttpGet httpget = new HttpGet("http://tweakers.net/nieuws/82969/amazon-nederland-opent-digitale-deuren-in-september.html");
          HttpResponse response = httpclient.execute(httpget);
          System.out.println("Execute finished");
          HttpEntity entity = response.getEntity();
          String page = readInput(entity.getContent());
          System.out.println("Request one finished without problems!");
  
          //Handle second request
          HttpGet httpost = new HttpGet("http://gathering.tweakers.net/forum/list_messages/1506977/last");
          response = httpclient.execute(httpost);
          entity = response.getEntity();
          page = readInput(entity.getContent());
          System.out.println("Request two finished without problems!");
      }
  
      private static String readInput(InputStream in) throws IOException {
          ByteArrayOutputStream out = new ByteArrayOutputStream();
          byte bytes[] = new byte[1024];
  
          int n = in.read(bytes);
  
          while (n != -1) {
              out.write(bytes, 0, n);
              n = in.read(bytes);
          }
  
          return new String(out.toString());
      }
  }
  </code></pre>
  
  <p>When runnig my example I get the folowing error</p>
  
  <pre><code>Request one finished without problems!
  Exception in thread "main" 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 ClientFormLogin.main(ClientFormLogin.java:29)
  Caused by: org.apache.http.HttpException: Unable to establish route: planned = {}-&gt;http://gathering.tweakers.net; current = {}-&gt;http://tweakers.net
      at org.apache.http.impl.client.DefaultRequestDirector.establishRoute(DefaultRequestDirector.java:842)
      at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:645)
      at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:480)
      at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
      ... 3 more
  </code></pre>
  
  <p>Any one can give me some pointers how I can solve this problem, except use a new <code>DefaultHttpClient</code> for every request.</p>
  
  <hr>
  
  <p><strong>Edit</strong></p>
  
  <p>I just found out if I stay on the same domain I have no problems so:</p>
  
  <pre><code>page1: 'http://tweakers.net/nieuws/82969/amazon-nederland-opent-digitale-deuren-in-september.html'
  page2: 'http://tweakers.net/nieuws/82973/website-nujij-belandt-op-zwarte-lijst-google-door-malware.html'
  </code></pre>
  
  <p>I have no problems if I got to:</p>
  
  <pre><code>page1: 'http://tweakers.net/nieuws/82969/amazon-nederland-opent-digitale-deuren-in-september.html'
  page2: 'http://gathering.tweakers.net/forum/list_messages/1506076/last'
  </code></pre>
  
  <p>I get the error.</p>
  
  <p>Ofc I see this one minute after posting my question. Except if someone can tell me how I can go 2 sperate domains with the same <code>DefaultHttpClient</code> my question is already answered.</p>