title: Android: How to call a website without loading it on app
body: <p>I wrote a web application in c# on visual studio, that runs a website which I can pass data to.
  How can I, in my android application, call this website URL with my appended data without doing any extra steps?</p>
  
  <p>I have been able to visit the website, but it loads the website on my application, I want to pass data to this website every second, so loading a web page every time is not the direction I'd like to head in.</p>
  
  <p>How can I just send the data to the website, loading as little data past that as possible?</p>
  
  <p>(When I write, while loading as little data as possible, I mean, that I don't want my application to visibly load the website and display it, I just want to call the website)</p>
  
  <p>Thank you for reading, and any direction you can provide for me!</p>
  
  <p>Update:
  This is the code I am currently trying to make work, it fails for some reason I cannot figure out</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
  private TextView urlReturn;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      String url = "http://10.0.2.2/test/Default.aspx";
      String urlParameters =
              null;
      try {
          urlParameters = "payload=" + URLEncoder.encode("AndroidTest", "UTF-8");
      } catch (UnsupportedEncodingException e) {
          e.printStackTrace();
      }
      urlReturn = (TextView)findViewById(R.id.webStatus);
      urlReturn.setText("Return: " + executePost(url, urlParameters));
  
  }
  public static String executePost(String targetURL, String urlParameters) {
      URL url;
      HttpURLConnection connection = null;
      try {
          //Create connection
          url = new URL(targetURL);
          connection = (HttpURLConnection) url.openConnection();
          connection.setRequestMethod("POST");
          connection.setRequestProperty("Content-Type",
                  "application/x-www-form-urlencoded");
  
          connection.setRequestProperty("Content-Length", "" +
                  Integer.toString(urlParameters.getBytes().length));
          connection.setRequestProperty("Content-Language", "en-US");
  
          connection.setUseCaches(false);
          connection.setDoInput(true);
          connection.setDoOutput(true);
  
          //Send request
          DataOutputStream wr = new DataOutputStream(
                  connection.getOutputStream());
          wr.writeBytes(urlParameters);
          wr.flush();
          wr.close();
  
          //Get Response
          InputStream is = connection.getInputStream();
          BufferedReader rd = new BufferedReader(new InputStreamReader(is));
          String line;
          StringBuffer response = new StringBuffer();
          while ((line = rd.readLine()) != null) {
              response.append(line);
              response.append('\r');
          }
          rd.close();
          return response.toString();
  
      } catch (Exception e) {
  
          e.printStackTrace();
          return "Fail!";
  
      } finally {
  
          if (connection != null) {
              connection.disconnect();
          }
      }
  }}
  </code></pre>
  
  <p>So this returns fail every time, I believe I'm not far off though...</p>
  
  <p>Update 2:
  I need to run the call in an Async task I believe, I will post my code upon completion.</p>