简体   繁体   English

E / Volley:[126] BasicNetwork.performRequest:意外的响应代码500

[英]E/Volley: [126] BasicNetwork.performRequest: Unexpected response code 500

why when i click on button "login" i have this error:" E/Volley: [126] BasicNetwork.performRequest: Unexpected response code 500 "? 为什么当我单击“登录”按钮时出现此错误:“ E/Volley: [126] BasicNetwork.performRequest: Unexpected response code 500 ”?

PS:it is works in local , so with local db. PS:它在local可用,因此对于local db。

this is my code:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 这是我的代码::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::

config.java: config.java:

public class Config {
    //URL to our login.php file
    //public static final String LOGIN_URL = "http://192.168.94.1/Android/LoginLogout/login.php";
   // public static final String LOGIN_URL = "http://10.0.2.2:8888/phpmyadmin/import.php#PMAURL-5:sql.php?db=androiddb&table=androiddb&server=1&target=&token=809562ca509cc18a182d0f6b0bef5485/login.php";
    //public static final String LOGIN_URL = "http://192.168.1.140/Android/LoginLogout/login.php";
    public static final String LOGIN_URL ="http://10.0.2.2:8888/androiddb/login.php";
    //Keys for email and password as defined in our $_POST['key'] in login.php
    public static final String KEY_EMAIL = "email";
    public static final String KEY_PASSWORD = "password";

    //If server response is equal to this that means login is successful
    public static final String LOGIN_SUCCESS = "success";

    //Keys for Sharedpreferences
    //This would be the name of our shared preferences
    public static final String SHARED_PREF_NAME = "myloginapp";

    //This would be used to store the email of current logged in user
    public static final String EMAIL_SHARED_PREF = "email";

    //We will use this to store the boolean in sharedpreference to track user is loggedin or not
    public static final String LOGGEDIN_SHARED_PREF = "loggedin";
}

LOGIN ACTIVITY.java: 登录ACTIVITY.java:

public class LoginActivity extends AppCompatActivity implements View.OnClickListener {

    //Defining views
    private EditText editTextEmail;
    private EditText editTextPassword;
    private AppCompatButton buttonLogin;

    //boolean variable to check user is logged in or not
    //initially it is false
    private boolean loggedIn = false;

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

        //Initializing views
        editTextEmail = (EditText) findViewById(R.id.editTextEmail);
        editTextPassword = (EditText) findViewById(R.id.editTextPassword);

        buttonLogin = (AppCompatButton) findViewById(R.id.buttonLogin);

        //Adding click listener
        buttonLogin.setOnClickListener(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        //In onresume fetching value from sharedpreference
        SharedPreferences sharedPreferences = getSharedPreferences(Config.SHARED_PREF_NAME,Context.MODE_PRIVATE);

        //Fetching the boolean value form sharedpreferences
        loggedIn = sharedPreferences.getBoolean(Config.LOGGEDIN_SHARED_PREF, false);

        //If we will get true
        if(loggedIn){
            //We will start the Profile Activity
            Intent intent = new Intent(LoginActivity.this, ProfileActivity.class);
            startActivity(intent);
        }
    }

    private void login(){
        //Getting values from edit texts
        final String email = editTextEmail.getText().toString().trim();
        final String password = editTextPassword.getText().toString().trim();

        //Creating a string request
        StringRequest stringRequest = new StringRequest(Request.Method.POST, Config.LOGIN_URL,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        //If we are getting success from server
                        if(response.equalsIgnoreCase(Config.LOGIN_SUCCESS)){
                            //Creating a shared preference
                            SharedPreferences sharedPreferences = LoginActivity.this.getSharedPreferences(Config.SHARED_PREF_NAME, Context.MODE_PRIVATE);

                            //Creating editor to store values to shared preferences
                            SharedPreferences.Editor editor = sharedPreferences.edit();

                            //Adding values to editor
                            editor.putBoolean(Config.LOGGEDIN_SHARED_PREF, true);
                            editor.putString(Config.EMAIL_SHARED_PREF, email);

                            //Saving values to editor
                            editor.commit();

                            //Starting profile activity
                            Intent intent = new Intent(LoginActivity.this, ProfileActivity.class);
                            startActivity(intent);
                        }else{
                            //If the server response is not success
                            //Displaying an error message on toast
                            Toast.makeText(LoginActivity.this, "Invalid username or password", Toast.LENGTH_LONG).show();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        //You can handle error here if you want
                    }
                }){
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String,String> params = new HashMap<>();
                //Adding parameters to request
                params.put(Config.KEY_EMAIL, email);
                params.put(Config.KEY_PASSWORD, password);
              //  params.put("Content-Type", "application/json; charset=utf-8");
                //returning parameter
                return params;
            }
        };

        //Adding the string request to the queue
        RequestQueue requestQueue = Volley.newRequestQueue(this);
        requestQueue.add(stringRequest);
    }

    @Override
    public void onClick(View v) {
        //Calling the login function
        login();
    }
}

DBConnect.php: DBConnect.php:

<?php
    define('HOST','localhost');
    define('USER',);
    define('PASS','');
    define('DB','androiddb');

    $con = mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect');

LOGIN.php: LOGIN.php:

<?php 

    if($_SERVER['REQUEST_METHOD']=='POST'){
        //Getting values 
        $username = $_POST['email'];
        $password = $_POST['password'];

        //Creating sql query
        $sql = "SELECT * FROM users WHERE email='$username' AND password='$password'";

        //importing dbConnect.php script 
        require_once('dbConnect.php');

        //executing query
        $result = mysqli_query($con,$sql);

        //fetching result
        $check = mysqli_fetch_array($result);

        //if we got some result 
        if(isset($check)){
            //displaying success 
            echo "success";
        }else{
            //displaying failure
            echo "failure";
        }
        mysqli_close($con);
    }

在此处输入图片说明

The problem is not your code but the server. 问题不是您的代码,而是服务器。 500 means Internal server error 500表示Internal server error

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 BasicNetwork.performRequest:意外的响应代码500 - BasicNetwork.performRequest: Unexpected response code 500 Volley - BasicNetwork.performRequest:意外的响应代码400 POST - Volley - BasicNetwork.performRequest: Unexpected response code 400 POST Volley BasicNetwork.performRequest:意外的响应代码 301 - Volley BasicNetwork.performRequest: Unexpected response code 301 Android Volley:BasicNetwork.performRequest:意外的响应代码404 - Android Volley: BasicNetwork.performRequest: Unexpected response code 404 E / Volley:[145] BasicNetwork.performRequest:https://的意外响应代码404 - E/Volley: [145] BasicNetwork.performRequest: Unexpected response code 404 for https:// BasicNetwork.performRequest:意外的响应代码500 Android - BasicNetwork.performRequest: Unexpected response code 500 Android BasicNetwork.performRequest:意外的响应代码413? - BasicNetwork.performRequest: Unexpected response code 413? BasicNetwork.performRequest:意外的响应代码422 - BasicNetwork.performRequest: Unexpected response code 422 如何修复“Volley:[15771] BasicNetwork.performRequest:Android 中的意外响应代码 404? - How to fix "Volley: [15771] BasicNetwork.performRequest: Unexpected response code 404 in android? BasicNetwork.performRequest:意外的响应代码400(GET) - BasicNetwork.performRequest: Unexpected response code 400 (GET)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM