title: How to set proxy host on HttpClient request in Java
body: <p>I want to set proxy before sending <code>HttpClient</code> request on a URL. As I am able to connect it curl command setting up the proxy but with Java code I am not able to do that. </p>
  
  <p>Curl command:</p>
  
  <pre><code>**curl -I -x IP:80  URL**
  </code></pre>
  
  <p>Code change done in java file:</p>
  
  <pre><code>HttpClient client = new HttpClient();
  System.getProperties().put("http.proxyHost", "someProxyURL");
  System.getProperties().put("http.proxyPort", "someProxyPort");
  EntityEnclosingMethod method = new PostMethod(url);
  method.setRequestEntity(new StringRequestEntity(requestXML, "text/xml", "utf-8"));
  </code></pre>
  
  <p>With above code changes in my java file I am getting below error :</p>
  
  <pre><code>java.net.ConnectException: Connection refused (Connection refused)
  </code></pre>
  
  <p>Which shows that I am not able to connect that URL with the proxy I am trying to use to connect the URL.</p>