title: How to send HTTP request from android app to Heroku
body: <p>I have a android app that uses the twilio sdk and is hosted by heroku server. I'm trying to push a button in my app to send a HTTP request to heroku to send a REST API request to Twilio to update my twiml URL. The current way i'm trying to send the the HTTP request is not working. I have looked through all of the examples that i could find and none of them show how to do this function. Does anybody know how to do this? Thanks in advance.</p>
  
  <p>This is my code for trying to send the HTTP request to heroku</p>
  
  <pre><code>    holdButton.setOnClickListener(new View.OnClickListener() {
  
  
          @Override
          public void onClick(View view) {
  
  
              HttpClient httpclient = new DefaultHttpClient();
              HttpPost httppost = new HttpPost("http://yourappnamehere.herokuapp.com/hello");
  
              try {
                  // Execute HTTP Post Request
                  HttpResponse response = httpclient.execute(httppost);
  
                  HttpEntity ht = response.getEntity();
  
                  BufferedHttpEntity buf = new BufferedHttpEntity(ht);
  
                  InputStream is = buf.getContent();
  
                  BufferedReader r = new BufferedReader(new InputStreamReader(is));
  
                  StringBuilder total = new StringBuilder();
                  String line;
                  while ((line = r.readLine()) != null) {
                      total.append(line);
                  }
  
              } catch (ClientProtocolException e) {
                  // TODO Auto-generated catch block
              } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
              //setting a toast to see if this is being initiated
              Toast.makeText(getBaseContext(), "why wont it work!", Toast.LENGTH_SHORT).show();
          }
  
          ;
  
      });
  </code></pre>
  
  <p>This is my updated code including the volley library</p>
  
  <pre><code>            holdButton.setOnClickListener(new View.OnClickListener() {
  
  
                  @Override
                  public void onClick(View view) {
                      //setting up a request queue from Volley API
                      //RequestQueue mRequestQueue;
  
      // Instantiate the cache
                      Cache cache = new DiskBasedCache(getCacheDir(), 1024 * 1024); // 1MB cap
  
      // Set up the network to use HttpURLConnection as the HTTP client.
                      Network network = new BasicNetwork(new HurlStack());
  
      // Instantiate the RequestQueue with the cache and network.
                      mRequestQueue = new RequestQueue(cache, network);
  
      // Start the queue
                      mRequestQueue.start();
  
                      String url = "http://yourappnamehere.herokuapp.com/hello";
  
      // Formulate the request and handle the response.
                      StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
                              new Response.Listener&lt;String&gt;() {
                                  @Override
                                  public void onResponse(String response) {
                                      // Do something with the response
                                  }
                              },
                              new Response.ErrorListener() {
                                  @Override
                                  public void onErrorResponse(VolleyError error) {
                                      // Handle error
                                  }
                              });
  
                      // Add the request to the RequestQueue.
                      mRequestQueue.add(stringRequest);
                      Toast.makeText(getBaseContext(), "why wont it work!", Toast.LENGTH_SHORT).show();
     }
  
     ;
  
     });
  </code></pre>