title: BasicNetwork.performRequest: Unexpected response code 500, Android Registration System
body: <p>I recently started working on my Android app and I needed a login and registration system. I found a tutorial on androidhive.info but I constantly get errors. I'm using a volley library for sending HTTP requests and the error in LogCat is related to that library. I used a public IP address of my server on DigitalOcean and I think it might have something to do with that because in the tutorial they store the php scripts on localhost. This is my android activity used for registering users:</p>
  
  <pre><code>package foi.hr.air.asocijacije.ui;
  
  import java.util.HashMap;
  import java.util.Map;
  
  import org.json.JSONException;
  import org.json.JSONObject;
  
  import com.android.volley.Request.Method;
  import com.android.volley.Response;
  import com.android.volley.VolleyError;
  import com.android.volley.toolbox.StringRequest;
  
  import android.app.Activity;
  import android.app.ProgressDialog;
  import android.content.Intent;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.Toast;
  import foi.hr.air.asocijacije.R;
  import foi.hr.air.asocijacije.db.SQLiteHandler;
  import foi.hr.air.asocijacije.main.AppConfig;
  import foi.hr.air.asocijacije.main.AppController;
  import foi.hr.air.asocijacije.main.MainActivity;
  
  public class RegisterActivity extends Activity {
  
  private static final String TAG = RegisterActivity.class.getSimpleName();
  private Button btnRegister;
  private Button btnLinkToLogin;
  private EditText inputName;
  private EditText inputSurname;
  private EditText inputEmail;
  private EditText inputPassword;
  private EditText inputPasswordRepeated;
  private ProgressDialog pDialog;
  private SessionManager session;
  private SQLiteHandler db;
  
  public void onCreate(Bundle savedBundleInstance) {
      super.onCreate(savedBundleInstance);
      setContentView(R.layout.register);
  
      inputName = (EditText) findViewById(R.id.name);
      inputSurname = (EditText) findViewById(R.id.surname);
      inputEmail = (EditText) findViewById(R.id.email);
      inputPassword = (EditText) findViewById(R.id.password);
      inputPasswordRepeated = (EditText) findViewById(R.id.passwordCheck);
      btnRegister = (Button) findViewById(R.id.btnRegister);
      btnLinkToLogin = (Button) findViewById(R.id.btnLinkToLoginScreen);
  
      pDialog = new ProgressDialog(this);
      pDialog.setCancelable(false);
  
      session = new SessionManager(getApplicationContext());
  
      db = new SQLiteHandler(getApplicationContext());
  
      if (session.isLoggedIn()) {
          Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
          startActivity(intent);
          finish();
      }
  
      btnRegister.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              String name = inputName.getText().toString();
              String surname = inputSurname.getText().toString();
              String email = inputEmail.getText().toString();
              String password = inputPassword.getText().toString();
              String passwordCheck = inputPasswordRepeated.getText().toString();
  
              if(name.isEmpty() || surname.isEmpty() || email.isEmpty() || password.isEmpty() || passwordCheck.isEmpty()) {
                  Toast.makeText(getApplicationContext(), "Please enter your details", Toast.LENGTH_LONG).show();
              }
              else {
                  if (password.equals(passwordCheck)){
                      registerUser(name, surname, email, password);
                  }
                  else {
                      Toast.makeText(getApplicationContext(), "Passwords don't match", Toast.LENGTH_LONG).show();
                  }
              }
          }
      });
  
      btnLinkToLogin.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Intent i = new Intent(getApplicationContext(), LoginActivity.class);
              startActivity(i);
          }
      });
  }
  
  private void registerUser(final String name, final String surname, final String email, final String password) {
  
  
  
      String tag_string_req = "req_register";
  
      pDialog.setMessage("Registering...");
      showDialog();
  
      StringRequest strReq = new StringRequest(Method.POST, AppConfig.URL_REGISTER, new Response.Listener&lt;String&gt;() {
          @Override
          public void onResponse(String response) {
              // TODO Auto-generated method stub
              Log.d(TAG, "Register response: " + response.toString());
              hideDialog();
  
              try {
                  JSONObject jObj = new JSONObject(response);
                  boolean error = jObj.getBoolean("error");
                  if(!error) {
                      String uid = jObj.getString("uid");
                      JSONObject user = jObj.getJSONObject("user");
                      String name = user.getString("name");
                      String surname = user.getString("surname");
                      String email = user.getString("email");
                      String created_at = user.getString("created_at");
  
                      db.addUser(uid, name, surname, email, created_at);
  
                      Intent intent = new Intent(RegisterActivity.this, LoginActivity.class);
                      startActivity(intent);
                      finish();
                  }
                  else {
                      String errorMsg = jObj.getString("errorMsg");
                      Toast.makeText(getApplicationContext(), errorMsg, Toast.LENGTH_LONG).show();
                  }
              }
              catch (JSONException e) {
                  e.printStackTrace();
              }
          }
      }, new Response.ErrorListener() {
          @Override
          public void onErrorResponse(VolleyError error) {
              // TODO Auto-generated method stub
              Log.e(TAG, "Registration error: " + error.getMessage());
              Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_LONG).show();
              hideDialog();
          }
      }) {
          @Override
          protected Map&lt;String, String&gt; getParams() {
              // TODO Auto-generated method stub
              Map&lt;String, String&gt; params = new HashMap&lt;String, String&gt;();
              params.put("tag", "register");
              params.put("name", name);
              params.put("surname", surname);
              params.put("email", email);
              params.put("password", password);
  
              return params;
          }
      };
      AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
  }
  
  private void showDialog() {
      if (!pDialog.isShowing()) {
          pDialog.show();
      }
  }
  
  private void hideDialog() {
      if(pDialog.isShowing()) {
          pDialog.dismiss();
      }
  }
  }
  </code></pre>
  
  <p>In my class AppConfig I stored the path to location where the php scripts are (Public IP)</p>
  
  <pre><code>package foi.hr.air.asocijacije.main;
  
  public class AppConfig {
  
  public static String URL_LOGIN = "http://95.85.57.105/android_login_api/";
  
  public static String URL_REGISTER = "http://95.85.57.105/android_login_api/";
  }
  </code></pre>
  
  <p>And this is the error log that I'm getting in LogCat</p>
  
  <pre><code>04-29 11:35:18.440: E/Volley(1742): [180] BasicNetwork.performRequest:   Unexpected response code 500 for http://95.85.57.105/android_login_api/
  04-29 11:35:18.916: E/RegisterActivity(1742): Registration error: null
  </code></pre>
  
  <p>I hope that you can help me get this thing right, I tried using POST method on Mozilla plugin HttpRequester to try to store data in my online MySQL database just to be sure that the php scripts are working fine, but I don't know what content should I send in JSON format. If needed I will post additional data so you could understand where the problem is.</p>