dongxu4023 2018-08-01 10:26
浏览 438

Android Studio - Volley:AuthFailureError

I want to create a App to register on MySQL. But everytime I want to register the Volley throws an AuthFailureError.

08-01 12:08:54.408 21235 21296 E Volley  : [10083] 
BasicNetwork.performRequest: Unexpected response code 403 for 
http://192.168.179.58:81/chatty/register.php

08-01 12:08:54.458 21235 21296 E Volley  : [10083] 
BasicNetwork.performRequest: Unexpected response code 403 for 
http://192.168.179.58:81/chatty/register.php

08-01 12:08:54.507 21235 21235 W System.err: 
com.android.volley.AuthFailureError

08-01 12:08:54.507 21235 21235 W System.err:    at 
com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:186)

08-01 12:08:54.508 21235 21235 W System.err:    at 
com.android.volley.NetworkDispatcher.processRequest
(NetworkDispatcher.java:120)

08-01 12:08:54.508 21235 21235 W System.err:    at 
com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:87)

I also turned off Firewall to check if that was the issue but nothing changed.

This is the register.php

<?php
$response = array();
include 'db/db_connect.php';
include 'functions.php';

//Get the input request parameters
$inputJSON = file_get_contents('php://input');
$input = json_decode($inputJSON, TRUE); //convert JSON into array

//Check for Mandatory parameters
if(isset($input['username']) && isset($input['password']) && 
isset($input['email'])){
$username = $input['username'];
$password = $input['password'];
$email = $input['email'];

//Check if user already exist
if(!userExists($username)){

    //Get a unique Salt
    $salt         = getSalt();

    //Generate a unique password Hash
    $passwordHash = 
password_hash(concatPasswordWithSalt($password,$salt),PASSWORD_DEFAULT);

    //Query to register new user
    $insertQuery  = "INSERT INTO member(username, email, password_hash, salt) 
VALUES (?,?,?,?)";
    if($stmt = $con->prepare($insertQuery)){
        $stmt->bind_param("ssss",$username,$email,$passwordHash,$salt);
        $stmt->execute();
        $response["status"] = 0;
        $response["message"] = "User created";
        $stmt->close();
    }
}
else{
    $response["status"] = 1;
    $response["message"] = "User exists";
}
}
else{
$response["status"] = 2;
$response["message"] = "Missing parameters";
}
echo json_encode($response);
?>

This is the SetupActivity.class

public class SetupActivity extends AppCompatActivity {

private EditText etusername;
private EditText etemail;
private EditText etpassword;
private EditText etconfirmpw;
private Button btnsetupnext;
private AVLoadingIndicatorView progressBar;
private static final String KEY_STATUS = "status";
private static final String KEY_MESSAGE = "message";
private static final String KEY_EMAIL = "email";
private static final String KEY_USERNAME = "username";
private static final String KEY_PASSWORD = "password";
private static final String KEY_EMPTY = "";
private String username;
private String password;
private String confirmPassword;
private String email;
private ProgressDialog pDialog;
private String register_url = "http://192.168.179.58:81/chatty/register.php";
private SessionHandler session;
private String body;

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

    etusername = (EditText) findViewById(R.id.accinfousername);
    etemail = (EditText) findViewById(R.id.accinfoemail);
    etpassword = (EditText) findViewById(R.id.accinfopassword);
    etconfirmpw = (EditText) findViewById(R.id.accinfopasswordconfirm);
    btnsetupnext = (Button) findViewById(R.id.btnNext);
    progressBar = (AVLoadingIndicatorView) findViewById(R.id.accinfoprogress);


    btnsetupnext.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

                    //Retrieve the data entered in the edit texts

                    username = etusername.getText().toString().toLowerCase().trim();
                    password = etpassword.getText().toString().trim();
                    confirmPassword = etconfirmpw.getText().toString().trim();
                    email = etemail.getText().toString().trim();
                    if (validateInputs()) {
                        progressBar.setVisibility(View.VISIBLE);
                        btnsetupnext.setVisibility(View.GONE);
                        registerUser();
                    }

        }
    });
}

private void displayLoader() {
    pDialog = new ProgressDialog(SetupActivity.this);
    pDialog.setMessage("Signing Up.. Please wait...");
    pDialog.setIndeterminate(false);
    pDialog.setCancelable(false);
    pDialog.show();

}
void sendUserToVerification() {
    Intent i = new Intent(getApplicationContext(), 
SetupVerificationActivity.class);
    startActivity(i);
    finish();

}

private void registerUser() {
    displayLoader();
    JSONObject request = new JSONObject();
    try {
        //Populate the request parameters
        request.put(KEY_USERNAME, username);
        request.put(KEY_PASSWORD, password);
        request.put(KEY_EMAIL, email);

    } catch (JSONException e) {
        e.printStackTrace();
    }
    JsonObjectRequest jsArrayRequest = new JsonObjectRequest
            (Request.Method.POST, register_url, request, new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    pDialog.dismiss();
                    try {
                        //Check if user got registered successfully
                        if (response.getInt(KEY_STATUS) == 0) {
                            //Set the user session
                            session.loginUser(username,email);
                            sendUserToVerification();

                        }else if(response.getInt(KEY_STATUS) == 1){
                            //Display error message if username is already existsing
                            etusername.setError("Username already taken!");
                            etusername.requestFocus();
                            progressBar.setVisibility(View.GONE);
                            btnsetupnext.setVisibility(View.VISIBLE);

                        }else{
                            Toast.makeText(getApplicationContext(),
                                    response.getString(KEY_MESSAGE), Toast.LENGTH_SHORT).show();
                            progressBar.setVisibility(View.GONE);
                            btnsetupnext.setVisibility(View.VISIBLE);
                            Toast.makeText(SetupActivity.this, "Error with JSONObject", Toast.LENGTH_SHORT).show();

                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {

                    pDialog.dismiss();
                    progressBar.setVisibility(View.GONE);
                    btnsetupnext.setVisibility(View.VISIBLE);
                    error.printStackTrace();
                    Toast.makeText(SetupActivity.this,
                            error.toString(), Toast.LENGTH_SHORT).show();
                }

            });

    // Access the RequestQueue through your singleton class.
    MySingleton.getInstance(this).addToRequestQueue(jsArrayRequest);
}


private boolean validateInputs() {
    if (KEY_EMPTY.equals(username)) {
        etusername.setError("Username cannot be empty");
        etusername.requestFocus();
        return false;
    }

    if (KEY_EMPTY.equals(email)) {
        etemail.setError("Email cannot be empty");
        etemail.requestFocus();
        return false;

    }

    if (KEY_EMPTY.equals(password)) {
        etpassword.setError("Password cannot be empty");
        etpassword.requestFocus();
        return false;
    }

    if (KEY_EMPTY.equals(confirmPassword)) {
        etconfirmpw.setError("Confirm Password cannot be empty");
        etconfirmpw.requestFocus();
        return false;
    }

    if(!password.equals(confirmPassword)) {
        etconfirmpw.setError("Password and Confirm Password doesn't match");
        etconfirmpw.requestFocus();
        return false;
    }


    return true;
}

}

The thing is when I try it with Postman it works:

Postman picture

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 请问这个是什么意思?
    • ¥15 STM32驱动继电器
    • ¥15 Windows server update services
    • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
    • ¥15 模糊pid与pid仿真结果几乎一样
    • ¥15 java的GUI的运用
    • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
    • ¥15 怎么配置广告联盟瀑布流
    • ¥15 Rstudio 保存代码闪退
    • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?