I have been following this tutorial to make a simple login / register database: http://ift.tt/1gfNOBZ
For some reason, when I try to log in or register I always get this error:
E/Volley﹕ [16019] BasicNetwork.performRequest: Unexpected response code 403 for http://192.168....
So I started to debug, and noticed that getParams() (used to insert data into the database) never gets called. Here is the method I'm using to register users:
private void registerUser(final String name, final String email,
final String password) {
StringRequest strReq = new StringRequest(Request.Method.POST,
AppConfig.URL_REGISTER, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(TAG, "Register Response: " + response.toString());
try {
JSONObject jObj = new JSONObject(response);
boolean error = jObj.getBoolean("error");
if (!error) {
// User successfully stored in MySQL
// Now store the user in sqlite
String uid = jObj.getString("uid");
JSONObject user = jObj.getJSONObject("user");
String name = user.getString("name");
String email = user.getString("email");
String created_at = user
.getString("created_at");
// Inserting row in users table
db.addUser(name, email, uid, created_at);
} else {
// Error occurred in registration. Get the error
// message
String errorMsg = jObj.getString("error_msg");
Toast.makeText(getActivity().getApplicationContext(),
errorMsg, Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Registration Error: " + error.getMessage());
Toast.makeText(getActivity().getApplicationContext(),
error.getMessage(), Toast.LENGTH_LONG).show();
}
}) {
@Override
protected Map<String, String> getParams() {
// Posting params to register url
Map<String, String> params = new HashMap<String, String>();
params.put("tag", "register");
params.put("name", name);
params.put("email", email);
params.put("password", password);
return params;
}
};
// Adding request to request queue
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
}
Does anyone know why this may be happening? I have already sweat 8 pints and probably grew a couple grey hairs trying to figure this out - any help is HIGHLY appreciated.
Thanks in advance for any insight! Please let me know if any more information is needed.
Aucun commentaire:
Enregistrer un commentaire