title: Send HTTP GET headers in Java
body: <p>I'm interested if it is possible to send HTTP GET headers with Java.</p>
  
  <p>Basically I'm working on a Java program that interfaces with a REST-like web-service. To mimic this I've created a small php file which simply outputs all the variables in <code>$_GET</code>, this way I can see if my GET header variables are correctly submitted.</p>
  
  <p>In php you can 'send' get variables by using the <code>?key=value</code> syntax, however I'm not sure if this works for every web platform. So I thought about sending these (key, value) pairs in the HTTP GET header (if this is not possible, or the wrong way to do it, feel free to point this out!).</p>
  
  <p>I've got the following code, but the response from the server doesn't echo any of the GET variables I send:</p>
  
  <pre><code> public static void Request(String address, Vector&lt;RequestProperty&gt; props){
          URL url = null;
          BufferedReader reader = null;
          StringBuilder stringBuilder;
          try{
              url = new URL(address);
              HttpURLConnection connection = (HttpURLConnection)url.openConnection();
              connection.setRequestMethod("GET");
              connection.setDoOutput(true);
  
              //Add request headers
              for(RequestProperty prop : props){
                  //Here I add the pairs like MyKey = MyValue
                  connection.addRequestProperty(prop.key,  prop.value);
              }
  
              connection.setReadTimeout(15000);
              connection.connect();
  
              reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
  
              String line = null;
              while((line = reader.readLine()) != null){
                  System.out.println(line);
              }
          }
          catch(Exception ex){
              ex.printStackTrace();
          }        
  </code></pre>