使用Response和JSON的Android Studio数据库连接

I'm trying to make a conection with my remote Database using a PHP file and JSONObject, but the code is skiping the Response.Listener and I don't know why... Here my Main that contains the Response.Listener:

Response.Listener<String> responseListener = new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {

                        Toast.makeText(Register.this, "Test00", Toast.LENGTH_SHORT).show();

                        JSONObject jsonObject = new JSONObject(response);
                        boolean success = jsonObject.getBoolean("success");

                        if(success)
                        {
                            Toast.makeText(Register.this, "Test01", Toast.LENGTH_SHORT).show();
                        }
                        else
                        {
                            Toast.makeText(Register.this, "Error", Toast.LENGTH_SHORT).show();
                        }

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

            RegisterRequest registerRequest = new RegisterRequest(email, username, usernick, password, birthdate, gender, responseListener);
            RequestQueue queue = Volley.newRequestQueue(Register.this);
            queue.add(registerRequest);

and here my RegisterRequest class:

public class RegisterRequest extends StringRequest {

private static final String REGISTER_REQUEST_URL = "kameo.com.br/control/ayzac_control_signin_mobile.php";
private Map<String, String> params;

public RegisterRequest(String email, String name, String nickname, String password, String date, String gender, Response.Listener<String> listener)
{
    super(Method.POST, REGISTER_REQUEST_URL, listener, null);
    params = new HashMap<>();
    params.put("userEmail", email);
    params.put("userName", name);
    params.put("userNickname", nickname);
    params.put("userPassword", password);
    params.put("userBirth", date);
    params.put("userGender", gender);
}

@Override
public Map<String, String> getParams() {
    return params;
}
}
du970294
du970294 它工作,只是在URL之前加上“http://”...非常感谢你!
接近 3 年之前 回复
dougang1967
dougang1967 检查您的请求参数
接近 3 年之前 回复
dpkt31779
dpkt31779 您是否尝试在apiURL之前添加http或https?
接近 3 年之前 回复

1个回答

I tested your URL and there is an error there: kameo.com.br/control/ayzac_control_signin_mobile.php

Also you need to read the error from your server response, try to create an error listener:

Response.Listener<String> errorListener = new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.e(TAG, "Error : " + error.getMessage());
            }
       };

And pass into your RegisterRequest constructor

dongmiao260399
dongmiao260399 用任何字符串替换TAG
接近 3 年之前 回复
douweidao3882
douweidao3882 您在Log中使用的TAG具有私人访问权限...
接近 3 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐