RequestQueue queue = Volley.newRequestQueue(getApplicationContext());
StringRequest sr = new StringRequest(Request.Method.POST, "URL" , new Response.Listener<String>() {
@Override
public void onResponse(String response) {
//Response
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
//ErrorListener
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("username", "username");
params.put("password", "password");
params.put("isAdmin", "boolean");
return params;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("Content-Type", "application/x-www-form-urlencoded");
return params;
}
};
queue.add(sr);
Try adding `charset=utf-8` to it. After much searching, that was what worked for me.
Credit: http://envyandroid.com/android-volley-empty-parameters/
RequestQueue queue = Volley.newRequestQueue(this);
StringRequest sr = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
pd.dismiss();
Log.d("Response: ", response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("Error: ", error + "");
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("name", name);
params.put("phone", phone);
params.put("email", email);
Log.d("getParams", params.toString());
return params;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
Log.d("getHeaders", params.toString());
return params;
}
};
queue.add(sr);