title: REST Client with content type JSON
body: <p>I am calling REST service with JSON request using Apache HTTPClient and it gives me 415 unsupported media type error. </p>
  
  <p>It works fine with some API but failed with the error:</p>
  
  <pre class="lang-java prettyprint-override"><code>DefaultHttpClient httpClient = new DefaultHttpClient();
  
  // Create new getRequest with below mentioned URL
  HttpGet getRequest = new HttpGet("example URL");
  
  String encoding = DatatypeConverter.printBase64Binary("usrname:pwd".getBytes("UTF-8"));
  getRequest.setHeader("Authorization", "Basic " + encoding);
  
  StringEntity params = new StringEntity("");
  
  params.setContentType("application/json");
  
  // Execute your request and catch response
  HttpResponse response = httpClient.execute(getRequest);
  
  // Check for HTTP response code: 200 = success
  if (response.getStatusLine().getStatusCode() != 200) {
      throw new RuntimeException("Failed : HTTP error code : " + 
          response.getStatusLine().getStatusCode());
  }
  
  // Get-Capture Complete application body response
  BufferedReader br = new BufferedReader(new InputStreamReader((
      response.getEntity().getContent())));
  String output;
  System.out.println("============Output:============");
  
  // Simply iterate through response and show on console.
  while ((output = br.readLine()) != null) {
  System.out.println(output);
  </code></pre>