title: Sending POST request in android studio
body: <p>I followed this <a href="https://www.androidhive.info/2014/01/how-to-create-rest-api-for-android-app-using-php-slim-and-mysql-day-12-2/" rel="nofollow noreferrer">article</a> to build my own RESTful API server before. Now, I would like to send a POST request to my API server in android studio. I followed this <a href="https://stackoverflow.com/a/35408890">reply</a>, but it is not successful.</p>
  
  <p>Here is part of my code:</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_events_create);
  
      ActionBar actionBar = this.getSupportActionBar();
      actionBar.setTitle("Test");
      actionBar.setDisplayHomeAsUpEnabled(true);
  
  
      URL url;
      HttpURLConnection connection = null;
      try {
          url = new URL("http://myip/task_manager/v1/register");
          connection = (HttpURLConnection)url.openConnection();
          connection.setDoOutput(true);
          connection.setRequestMethod("POST"); // hear you are telling that it is a POST request, which can be changed into "PUT", "GET", "DELETE" etc.
          connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); // here you are setting the `Content-Type` for the data you are sending which is `application/json`
          connection.connect();
  
          //Send request
          DataOutputStream wr = new DataOutputStream(
                  connection.getOutputStream ());
          wr.writeBytes("Parameter String"); // I dunno how to write this string..
          wr.flush();
          wr.close ();
  
          InputStream is;
          int response = connection.getResponseCode();
          if (response &gt;= 200 &amp;&amp; response &lt;=399){
              //return is = connection.getInputStream();
              //return true;
          } else {
              //return is = connection.getErrorStream();
              //return false;
          }
  
  
      } catch (Exception e) {
  
          e.printStackTrace();
          //return false;
  
      } finally {
  
          if(connection != null) {
              connection.disconnect();
          }
      }
  
  }
  </code></pre>
  
  <p>Here is my questions:<br>
  1. When "connection.connect();" is run, there is error in console. Is my url string is wrong?<br>
  2. What should the "Parameter String" be like? (my parameters are email=xxx, name=yyy)<br>
  3. Is there any better method to send a POST request?<br><br></p>
  
  <p>Thanks a lot!!!!!!~</p>