title: Get request in java application using application/x-www-form-urlencoded format
body: <p>When I try and send a request to my server, the server only gets POST requests no matter if I set setRequestMethod("GET") . This is the function I am calling, with an url and 2 params I need to send with them: </p>
  
  <pre><code>public static String getHTML(String urlToRead,String urlParameters) {
      try {
          StringBuilder result = new StringBuilder();
          URL url = new URL(urlToRead);
          HttpURLConnection conn = (HttpURLConnection) url.openConnection();
          conn.setRequestMethod("GET");
          conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
          conn.setRequestProperty("Content-Length", Integer.toString(urlParameters.getBytes().length));
  
          conn.setUseCaches(false);
          conn.setDoOutput(true);
  
          DataOutputStream wr = new DataOutputStream (
              conn.getOutputStream());
              wr.writeBytes(urlParameters);
              wr.close();
  
              BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
              String line;
              while ((line = rd.readLine()) != null) {
                  result.append(line);
              }
  
              rd.close();
              return result.toString();
          }
          catch (Exception e) {
              return e.getMessage().toString();
          }
      }
  }
  </code></pre>
  
  <p>Any help is welcome or any other functions to be able to send a GET request to a server by sending the URL and two parameters.</p>