BasicNetwork.performRequest:登录时出现意外响应代码500

时间:2018-07-31 13:25:21

标签: java php android-studio android-volley http-response-codes

几个小时以来,登录到我的应用程序时,总是遇到500错误。我已经知道错误的含义。但是,我也想知道如何解决它。

这是我的密码:

<?php
$mysqli = new mysqli("localhost","id6640581_m8finder_db","***my db-password***","id6640581_m8finder_db");

$benutzername = $_POST["benutzername"];
$passwort = $_POST["passwort"];

$statement = mysqli_prepare($con, "SELECT * FROM benutzer WHERE benutzername = ? AND passwort = ?");
mysqli_stmt_bind_param($statement, "ss", $benutzername, $passwort);
mysqli_stmt_execute($statement);

mysqli_stmt_store_result($statement);
mysqli_stmt_bind_result($statement, $userID, $vorname, nachname, $benutzername, $passwort);

$response = array();
$response["success"] = false;

while(mysqli_stmt_fetch($statement)){
    $response["success"] = true;
    $response["vorname"] = $vorname;
    $response["nachname"] = $nachname;
    $response["benutzername"] = $benutzername;
    $response["passwort"] = $passwort;
}

echo json_encode($response);
?>

这是我的LoginRequest Java.class

public class LoginRequest extends StringRequest {
private static final String LOGIN_REQUEST_URL = "https://m8finder.000webhostapp.com/login.php";
private Map<String, String> params;

public LoginRequest(String benutzername, String passwort, Response.Listener<String> listener) {
    super(Method.POST, LOGIN_REQUEST_URL, listener, null);
    params = new HashMap<>();
    params.put("benutzername", benutzername);
    params.put("passwort", passwort);
}

@Override
public Map<String, String> getParams() {
    return params;
}

最后是我的LoginActivity类

public class LoginActivity extends AppCompatActivity implements View.OnClickListener{

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    final EditText editUsername = (EditText) findViewById(R.id.editUsername);
    final EditText editPassword = (EditText) findViewById(R.id.editPassword);
    final CardView login = (CardView) findViewById(R.id.card_login);

    login.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final String benutzername = editUsername.getText().toString();
            final String passwort = editPassword.getText().toString();

            // Response received from the server
            Response.Listener<String> responseListener = new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        JSONObject jsonResponse = new JSONObject(response);
                        boolean success = jsonResponse.getBoolean("success");

                        if (success) {
                            String vorname = jsonResponse.getString("vorname");
                            String nachname = jsonResponse.getString("nachname");

                            Intent intent = new Intent(LoginActivity.this, MainActivity.class);
                            intent.putExtra("vorname", vorname);
                            intent.putExtra("nachname", nachname);
                            intent.putExtra("benutzername", benutzername);
                            LoginActivity.this.startActivity(intent);
                        } else {
                            AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
                            builder.setMessage("Einloggen fehlgeschlagen.")
                                    .setNegativeButton("Nochmal versuchen.", null)
                                    .create()
                                    .show();
                        }

                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            };

            LoginRequest loginRequest = new LoginRequest(benutzername, passwort, responseListener);
            RequestQueue queue = Volley.newRequestQueue(LoginActivity.this);
            queue.add(loginRequest);
        }
    });

    CardView card_back = (CardView) findViewById(R.id.card_back);
    card_back.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });

    CardView card_forget = (CardView) findViewById(R.id.card_forget);
    card_forget.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent in = new Intent(getApplicationContext(),PasswortActivity.class);
            startActivity(in);
        }
    });
}

@Override
public void onClick(View v) {
}}

我不知道为什么,但是当我要登录时,总是会出现此错误。

  

E / Volley:[****] BasicNetwork.performRequest:https://m8finder.000webhostapp.com/login.php的意外响应代码500

0 个答案:

没有答案