title: How to send http post request from Android?
body: <p>I'm new to android and now I'm so tired of searching the best tutorial about android HTTP requests.</p>
  
  <p>I'm trying to send these parameters to phpServer,</p>
  
  <ul>
  <li><p>Name = "some name"</p></li>
  <li><p>email = "some email"</p></li>
  </ul>
  
  <p>Can we do this in MainActivity.java file? is this need any jar(library) file?
  any suggestions are welcome.</p>
  
  <p>I tried this,</p>
  
  <pre><code>@Override
  public void onClick(View view) {
      if(view == btnSubscribe){
          HttpURLConnection client = null;
          try {
              URL url = new URL("http://www/somewebsite.com/API/SUBSCRIBE");
              client = (HttpURLConnection) url.openConnection();
              client.setRequestMethod("POST");
              client.setRequestProperty("name","test one");
              client.setRequestProperty("email","text@gmail.com");
              client.setDoOutput(true);
  
              OutputStream outputPost = new BufferedOutputStream(client.getOutputStream());
              outputPost.flush();
              outputPost.close();
              client.setChunkedStreamingMode(0);
  
          } catch(MalformedURLException error) {
              showError("Handles an incorrectly entered UR");
          }
          catch(SocketTimeoutException error) {
              showError("Handles URL access timeout");
          }
          catch (IOException error) {
              showError("Handles input and output errors");
          }finally {
              if(client != null)
              client.disconnect();
          }
      }
  }
  </code></pre>