title: Send request to Google Elevation API in Java
body: <p>I'm try to send Post request to Google elevation API and expecting response </p>
  
  <pre><code>private final String ELEVATION_API_URL =  "https://maps.googleapis.com/maps/api/elevation/json";
  
  private final String USER_AGENT = "Mozilla/5.0";
  
  String urlParameters = "locations=6.9366681,79.9393521&amp;sensor=true&amp;key=&lt;API KEY&gt;";
  
  
  URL obj = new URL(ELEVATION_API_URL);
              java.net.HttpURLConnection con = (java.net.HttpURLConnection)obj.openConnection();
  
              //add reuqest header
              con.setRequestMethod("POST");
              con.setRequestProperty("User-Agent", USER_AGENT);
              con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
              con.setRequestProperty("Content-Language", "en-US");  
  
              String urlParameters = request;
  
              // Send post request
              con.setDoOutput(true);
              DataOutputStream wr = new DataOutputStream(con.getOutputStream());
              wr.writeBytes(urlParameters);
              wr.flush();
              wr.close();
  
              int responseCode = con.getResponseCode();
  </code></pre>
  
  <p>I'm sending request in this manner but I'm getting response code as 400.This is working when request sent from browser. What is wrong with this code.</p>