title: Apache httpComponents HttpClient 4.2.2 unable connect to a web page via Webscarab proxy
body: <p>I have a method which uses the Apache httpComponents HttpClient class to connect to a web page via the Webscarab proxy. I get the method from the Apache Software Foundation  <a href="http://hc.apache.org/httpcomponents-client-ga/httpclient/examples/org/apache/http/examples/client/ClientExecuteProxy.java" rel="nofollow noreferrer">here</a>. below is my hole method:</p>
  <pre><code>       public void HTTPGet(){
              //HttpHost proxy = new HttpHost(&quot;localhost&quot;, 8008);
  
              System.setProperty(&quot;http.proxyHost&quot;, &quot;localhost&quot;);
              System.setProperty(&quot;http.proxyPort&quot;, &quot;8008&quot;);
  
              HttpHost proxy = new HttpHost(System.getProperty(&quot;http.proxyHost&quot;, &quot;localhost&quot;),Integer.parseInt(System.getProperty(&quot;http.proxyPort&quot;, &quot;8008&quot;)));
                  
              DefaultHttpClient httpclient = new DefaultHttpClient();
              try {
  
                  httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
                          proxy);
  
                  HttpHost target = new HttpHost(&quot;www.google.gr/&quot;, 80);
                  HttpGet req = new HttpGet(&quot;/&quot;);
  
                  System.out.println(&quot;executing request to &quot; + target + &quot; via &quot;
                          + proxy);
                  HttpResponse rsp = httpclient.execute(target, req); //here I get the exception as below
                  HttpEntity entity = rsp.getEntity();
  
                  System.out.println(&quot;----------------------------------------&quot;);
                  System.out.println(rsp.getStatusLine());
                  Header[] headers = rsp.getAllHeaders();
                  for (int i = 0; i &lt; headers.length; i++) {
                      System.out.println(headers[i]);
                  }
                  System.out.println(&quot;----------------------------------------&quot;);
  
                  if (entity != null) {
                      System.out.println(EntityUtils.toString(entity));
                  }
  
              } catch (IOException ex) {
                  Logger.getLogger(WebBrowser.class.getName()).log(Level.SEVERE, null, ex);
              } 
              finally {
                  // When HttpClient instance is no longer needed,
                  // shut down the connection manager to ensure
                  // immediate deallocation of all system resources
                  httpclient.getConnectionManager().shutdown();
              }
        }
  </code></pre>
  <p>The println before the <code>HttpResponse rsp = httpclient.execute(target, req);</code>,</p>
  <p>return this : <code>executing request to http://www.google.gr/:80 via http://localhost:8008</code></p>
  <p>Then the below exception occurs.</p>
  <pre><code>Nov 28, 2012 1:23:09 AM student.WebBrowser HTTPGet
  SEVERE: null
  org.apache.http.conn.HttpHostConnectException: Connection to http://localhost:8008 refused
  at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:190)
  at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:294)
  at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:640)
  at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:479)
  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:827)
  </code></pre>
  <p>Webscarab interfere correctly when I try to reach a page from another browser, like Firefox, Chrome or JavaFX webengine.</p>
  <p>Thanks in advance.</p>