title: How do I add query parameters to a GetMethod (using Java commons-httpclient)?
body: <p>Using Apache's commons-httpclient for Java, what's the best way to add query parameters to a GetMethod instance? If I'm using PostMethod, it's very straightforward:</p>
  
  <pre><code>PostMethod method = new PostMethod();
  method.addParameter("key", "value");
  </code></pre>
  
  <p>GetMethod doesn't have an "addParameter" method, though. I've discovered that this works:</p>
  
  <pre><code>GetMethod method = new GetMethod("http://www.example.com/page");
  method.setQueryString(new NameValuePair[] {
      new NameValuePair("key", "value")
  });
  </code></pre>
  
  <p>However, most of the examples I've seen either hard-code the parameters directly into the URL, e.g.:</p>
  
  <pre><code>GetMethod method = new GetMethod("http://www.example.com/page?key=value");
  </code></pre>
  
  <p>or hard-code the query string, e.g.:</p>
  
  <pre><code>GetMethod method = new GetMethod("http://www.example.com/page");
  method.setQueryString("?key=value");
  </code></pre>
  
  <p>Is one of these patterns to be preferred? And why the API discrepancy between PostMethod and GetMethod? And what are all those other HttpMethodParams methods intended to be used for?</p>