title: How to set parameters in a GET request in Java
body: <p>So I want to send a GET request with parameters. But it only seems to have conventions for the url you send the request to. Unlike the POST request, I see no way to pass parameters in it.</p>
  
  <p>How I send the GET request now, without parameters (might be wrong):</p>
  
  <pre><code>String url = "http://api.netatmo.net/api/getuser";
  
              URL obj = new URL(url);
              HttpURLConnection con = (HttpURLConnection) obj.openConnection();
  
              // optional default is GET
              con.setRequestMethod("GET");
  
              //add request header
              con.setRequestProperty("User-Agent", USER_AGENT);
  
              int responseCode = con.getResponseCode();
              Log.v(TAG, ("\nSending 'GET' request to URL : " + url));
              Log.v(TAG, ("Response Code : " + responseCode));
  
              BufferedReader in = new BufferedReader(
                      new InputStreamReader(con.getInputStream()));
              String inputLine;
              StringBuffer response = new StringBuffer();
  
              while ((inputLine = in.readLine()) != null) {
                  response.append(inputLine);
              }
              in.close();
  
              //print result
              Log.v(TAG, (response.toString()));
  </code></pre>
  
  <p>How I send the POST request with parameters:</p>
  
  <pre><code>String url = "https://api.netatmo.net/oauth2/token";
              URL obj = new URL(url);
              HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
  
              //add request header
              con.setRequestMethod("POST");
              con.setRequestProperty("User-Agent", USER_AGENT);
              con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
  
              String urlParameters = "grant_type=password&amp;client_id=myid&amp;client_secret=mysecret&amp;username=myusername&amp;password=mypass";
  
              // Send post request
              con.setDoOutput(true);
              DataOutputStream wr = new DataOutputStream(con.getOutputStream());
              wr.writeBytes(urlParameters);
              wr.flush();
              wr.close();
  
              int responseCode = con.getResponseCode();
              Log.v(TAG, "\nSending 'POST' request to URL : " + url);
              Log.v(TAG, "Post parameters : " + urlParameters);
              Log.v(TAG, "Response Code : " + responseCode);
  
              BufferedReader in = new BufferedReader(
                      new InputStreamReader(con.getInputStream()));
              String inputLine;
              StringBuffer response = new StringBuffer();
  
              while ((inputLine = in.readLine()) != null) {
                  response.append(inputLine);
              }
              in.close();
  
              //print result
              Log.v(TAG, response.toString());
  
              access_token = response.substring(17, 74);
              refresh_token = response.substring(93,150);
              getRequest = "/api/getuser?access_token=" + access_token + " HTTP/1.1";
  
              Log.v(TAG, access_token);
              Log.v(TAG, refresh_token);
              Log.v(TAG, getRequest);
  </code></pre>