title: HttpClient exception: java.lang.IllegalArgumentException: host parameter is null while sending a request using using GetMethod()
body: <p>First of all my question is not duplicate to others. I am querying my question from last 2 days but didn't found any solution.The solutions I found were for the <code>PostMethod</code> but I have issue is <code>GetMethod</code>.
  Due to some confidential data issue I cannot share the exact endpointUrl but I am giving a dummy endpointUrl.
  below code was working fine and returning a csv file until the <code>endPointUrl</code> was  <code>https://abcxyz.com/incident.do?CSV</code> (abcxyz is the only dummy part here), :</p>
  
  <pre><code>HttpClient client = new HttpClient();
  client.getParams().setAuthenticationPreemptive(true);
  Credentials creds = new UsernamePasswordCredentials(userName, password);
  client.getState().setCredentials(AuthScope.ANY, creds);
  
  GetMethod method=new GetMethod(endPointUrl);
  int status = client.executeMethod(method); 
  </code></pre>
  
  <p>Then I came in need to change endPointUrl which became  <code>https://abcxyz.com/incident.do?CSV&amp;sys_param_query=active=true^sys_updated_onBETWEENjavascript:gs.dateGenerate(%272016-11-20%27,%2700:10:00%27)@javascript:gs.dateGenerate(%272016-11-24%27,%2712:59:59%27)</code> and then the above code started giving <code>java.lang.IllegalArgumentException: Invalid uri</code> exception. Then I googled this and found that for larger urls or complex url we need to encode(UTF-8) them correctly using <code>URLEncoder.encode(endPointUrl, UTF-8)</code>. And the code became :</p>
  
  <pre><code>HttpClient client = new HttpClient();
  client.getParams().setAuthenticationPreemptive(true);
  Credentials creds = new UsernamePasswordCredentials(userName, password);
  client.getState().setCredentials(AuthScope.ANY, creds);
  
  GetMethod method=new GetMethod(URLEncoder.encode(endPointUrl, UTF-8));
  int status = client.executeMethod(method);
  </code></pre>
  
  <p>Now this code started complaining about <code>java.lang.IllegalArgumentException: host parameter is null</code>
  Again I tried to solve this and came up with some solution as below: </p>
  
  <pre><code>HttpClient client = new HttpClient();
  client.getParams().setAuthenticationPreemptive(true);
  Credentials creds = new UsernamePasswordCredentials(userName, password);
  client.getState().setCredentials(AuthScope.ANY, creds);
  
  HostConfiguration hf=new HostConfiguration();
  hf.setHost("ven01623.service-now.com", 443); 
  GetMethod method=new GetMethod(URLEncoder.encode(endPointUrl, UTF-8));
  method.setHostConfiguration(hf);
  int status = client.executeMethod(method);
  </code></pre>
  
  <p>But now, it is complaining <code>org.apache.commons.httpclient.URIException: invalid port number</code> and I have no clue what to do now because it is a https connection to which has port number 443.</p>
  
  <p>I am having one more question here, <code>https://abcxyz.com/incident.do?CSV</code> is running fine under <code>GetMethod method=new GetMethod(endPointUrl);</code> then why is it complaining <strong>host parameter is null</strong> under <code>GetMethod method=new GetMethod(URLEncoder.encode(endPointUrl, UTF-8));</code> ?
  In Very much need of help.
  Thanks</p>