title: Sending a network request with a JSON header
body: <p>So, I have a method that sends a request to a webserver and grabs a response and stores it into a string.</p>
  
  <p>My problem is that it returns XML by default, but I wan it to return JSON. The guy working on the server side said "it defaults to XML, but you can send the request with a JSON header, and it'll return that." </p>
  
  <p>So, my question is, what do I have to do to request JSON data coming back instead of XML? (By the way, the guy on the server side isn't available to answer this question)</p>
  
  <p>Thanks for the help</p>
  
  <pre><code>public class NetworkRequest {
  private List&lt;NameValuePair&gt; nameValuePairs;
  private String URL;
  
  public NetworkRequest(List&lt;NameValuePair&gt; nameValuePairs) {
      this.nameValuePairs = nameValuePairs;
  }
  
  public String sendRequest() {
      String result = "";
      InputStream isr = null;
      try {
          HttpClient httpclient = new DefaultHttpClient();
          HttpPost httppost = new HttpPost(URL);
  
          httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  
          HttpResponse response = httpclient.execute(httppost);
          HttpEntity entity = response.getEntity();
          isr = entity.getContent();
      } catch (Exception e) {
          Log.e("log_tag", "Error in http connection " + e.toString());
      }
      // convert response to string
      try {
          BufferedReader reader = new BufferedReader(new InputStreamReader(
                  isr, "iso-8859-1"), 8);
          StringBuilder sb = new StringBuilder();
          String line = null;
          while ((line = reader.readLine()) != null) {
              sb.append(line + "\n");
          }
          isr.close();
  
          result = sb.toString();
      } catch (Exception e) {
          Log.e("log_tag", "Error  converting result " + e.toString());
      }
      return result;
  }
  
  public void setURL(String URL) {
      this.URL = URL;
  }
  }
  </code></pre>