title: Binding HttpClient 4.1 request to local address
body: <p>Getting error while binding HttpClient request through a specific localAddress</p>
  
  <p>this is the code</p>
  
  <pre><code>    HttpParams httpsParams = new BasicHttpParams();
      ConnRouteParams.setLocalAddress(httpsParams, InetAddress.getByAddress(new byte[]{ (byte)192, (byte)168, (byte)43, (byte)98 }));
  
      DefaultHttpClient httpClient = new DefaultHttpClient(httpsParams);
  
      URL url = new URL("http://what-is-my-ip.net/?json");
  
      HttpGet method = new HttpGet(url.toURI());
  
      HttpResponse response = httpClient.execute(method);
      InputStream is = response.getEntity().getContent();
  
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
  
      byte[] buffer = new byte[1024];
      int nbRead;
      while ((nbRead = is.read(buffer)) != -1) {
          bos.write(buffer, 0, nbRead);
      }
  
      is.close();
  
      System.out.println(new String(bos.toByteArray()));
  </code></pre>
  
  <p>and this is the error</p>
  
  <pre><code>Oct 26, 2012 10:48:57 PM org.apache.http.impl.client.DefaultRequestDirector tryConnect
  INFO: I/O exception (java.net.SocketException) caught when connecting to the target host: Network is unreachable: connect
  Oct 26, 2012 10:48:57 PM org.apache.http.impl.client.DefaultRequestDirector tryConnect
  INFO: Retrying connect
  Oct 26, 2012 10:48:57 PM org.apache.http.impl.client.DefaultRequestDirector tryConnect
  INFO: I/O exception (java.net.SocketException) caught when connecting to the target host: Network is unreachable: connect
  Oct 26, 2012 10:48:57 PM org.apache.http.impl.client.DefaultRequestDirector tryConnect
  INFO: Retrying connect
  Oct 26, 2012 10:48:57 PM org.apache.http.impl.client.DefaultRequestDirector tryConnect
  INFO: I/O exception (java.net.SocketException) caught when connecting to the target host: Network is unreachable: connect
  Oct 26, 2012 10:48:57 PM org.apache.http.impl.client.DefaultRequestDirector tryConnect
  INFO: Retrying connect
  Exception in thread "main" java.net.SocketException: Network is unreachable: connect
      at java.net.DualStackPlainSocketImpl.connect0(Native Method)
      at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69)
      at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
      at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
      at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
      at java.net.Socket.connect(Socket.java:579)
      at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:123)
      at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:148)
      at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:149)
      at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:121)
      at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:573)
      at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:425)
      at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
      at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
      at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)
      at utils.NewClass.main(NewClass.java:49)
  </code></pre>
  
  <p>Am i doing something wrong ?
  Please help, i googled a lot but couldnt find anything on this.</p>
  
  <p>Is this an OS related problem, im on win7 ?</p>
  
  <p>Any help wld be appreciated.</p>