title: Android Http Get Request
body: <p>I'm a newbie at android development. I'm trying to send a GET request to an URL. I wrote the below code. </p>
  
  <pre><code>public void searchProducts(View v) 
  {
      //String txtSearchTerm = ((EditText)findViewById(R.id.txtsearch)).getText().toString();
      //String termCleaned = txtSearchTerm.replace(' ', '+').toString();
      AlertDialog alertMessage = new AlertDialog.Builder(this).create();
      alertMessage.setTitle("Loading");
      alertMessage.setMessage(GET("http://webkarinca.com/sample.json"));
      alertMessage.show(); 
  } 
  public static String GET(String url){
      InputStream inputStream = null;
      String result = "";
      try {
  
          HttpClient httpclient = new DefaultHttpClient();
          HttpResponse httpResponse = httpclient.execute(new HttpGet(url));
          inputStream = httpResponse.getEntity().getContent();
          if(inputStream != null)
          {
              result = convertInputStreamToString(inputStream);
          }
          else
          {
              result = "Did not work!";
          }
  
      } catch (Exception e) {
          Log.d("InputStream", e.getLocalizedMessage());
      }
  
      return result;
  }
  private static String convertInputStreamToString(InputStream inputStream) throws IOException{
      BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(inputStream));
      String line = "";
      String result = "";
      while((line = bufferedReader.readLine()) != null)
          result += line;
  
      inputStream.close();
      return result;
  
  }
  </code></pre>
  
  <p>I already put imports head of the class. There they are</p>
  
  <pre><code>import org.apache.http.HttpResponse;
  import org.apache.http.client.methods.HttpGet;
  import org.apache.http.impl.client.DefaultHttpClient;
  import org.json.JSONObject;
  </code></pre>
  
  <p>It doesn't work and at the Problems section it shows as a warning</p>
  
  <p>The type HttpGet is deprecated
  The type HttpResponse is deprecated</p>