BasicNetwork.performRequest: Unexpected response code 500, Android registration system

I recently started working on my Android app and I need a registration and registration system. I found a tutorial on androidhive.info but I keep getting errors. I am using volley library to send HTTP requests and the error in LogCat is related to this library. I used the public IP of my server on DigitalOcean and I think it might have something to do with this because in the tutorial they store php scripts on localhost. This is my android activity used to register users:

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<String>() {
        @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<String, String> getParams() {
            // TODO Auto-generated method stub
            Map<String, String> params = new HashMap<String, String>();
            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();
    }
}
}

      

In my AppConfig class, I have saved the path to where php scripts (Public IP)

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/";
}

      

And this is the error log I am getting in the LogCat

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

      

I hope you can help me understand this thing correctly, I tried using the POST method in the HttpRequester module for Mozilla to try and save the data to my online MySQL database to make sure the php scripts are working fine, but I don't know. t know what content should be sent in JSON format. I will send additional details if necessary so you can understand where the problem is.

+3


source to share


1 answer


Shouldn't it be

public static String URL_LOGIN = "http://95.85.57.105/android_login_api/login.php";

public static String URL_REGISTER = "http://95.85.57.105/android_login_api/register.php";

      

I'm not sure if the error you picked is exactly 404 or 500, but try it anyway.

EDIT: (Updated December 9, 2015)



First of all. The 500 error is a server error and the issue can be resolved by checking the logs first. Go to your android_login_api folder on your server and add these two lines

error_reporting(-1);
ini_set('display_errors', 'On');

      

Now your Android Studio will show an error log and what the problem really is. I faced the same problem and after looking at the error, the problem was with the database connection. If you still find this problem persists, you can use the POSTMAN or RESTAPI client extension on google and check if the given url works on your server. This should help.

0


source







All Articles