title: Getting responsecode 500 on poset request in android app
body: <p>I am trying to implement post request to my android application. But unfortunately I am getting status code 500 in response. Here is my code</p>
  
  <pre><code>public class SendPostRequest extends AsyncTask&lt;String, Void, String&gt; {
  
          protected void onPreExecute(){}
  
          protected String doInBackground(String... arg0) {
  
              try {
  
                  URL url = new URL("http://serveruri/auth/register"); // here is your URL path
  
                  JSONObject postDataParams = new JSONObject();
                  postDataParams.put("username", "abcdsdgvsdf");
                  postDataParams.put("password", "abcmail");
                  postDataParams.put("email", "abc@gmail.com");
  
                  Log.e("params",postDataParams.toString());
  
                  HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                  conn.setReadTimeout(15000 /* milliseconds */);
                  conn.setConnectTimeout(15000 /* milliseconds */);
                  conn.setRequestMethod("POST");
                  conn.setRequestProperty("Accept", "application/json");
                  conn.setRequestProperty("Content-Type", "application/json");
                  conn.setDoInput(true);
                  conn.setDoOutput(true);
  
                  OutputStream os = conn.getOutputStream();
                  BufferedWriter writer = new BufferedWriter(
                          new OutputStreamWriter(os, "UTF-8"));
                  writer.write(getPostDataString(postDataParams));
  
                  writer.flush();
                  writer.close();
                  os.close();
  
                  int responseCode=conn.getResponseCode();
                  Log.d("responsecode", String.valueOf(responseCode));
  
                  if (responseCode == HttpsURLConnection.HTTP_OK) {
  
                      BufferedReader in=new BufferedReader(new
                              InputStreamReader(
                              conn.getInputStream()));
  
                      StringBuffer sb = new StringBuffer("");
                      String line="";
  
                      while((line = in.readLine()) != null) {
  
                          sb.append(line);
                          break;
                      }
  
                      in.close();
                      return sb.toString();
  
                  }
                  else {
                      return new String("false : "+responseCode);
                  }
              }
              catch(Exception e){
                  return new String("Exception: " + e.getMessage());
              }
  
          }
  
          @Override
          protected void onPostExecute(String result) {
              Toast.makeText(getApplicationContext(), result,
                      Toast.LENGTH_LONG).show();
          }
      }
  </code></pre>
  
  <p>I tested the same uri on postman and it is working.</p>
  
  <p>What is the problem here? How can I solve this issue?</p>