pierre-charles Mangin pierre-charles Mangin - 11 months ago 144
PHP Question

Android - Volley Error 403 won't be solved

I'm actually trying to create a login activity using volley but i can't understand why it always give me the

error 403 : unexpected response

I know that my php code is as good as my server because i tryed it with Postman and it work just fine.
(Internet permission is activated)

public class LoginActivity extends AppCompatActivity {
private EditText email,password;
private Button sign_in_register;
private RequestQueue requestQueue;
private static final String URL = "";
private StringRequest request;

protected void onCreate(final Bundle savedInstanceState) {

email = (EditText) findViewById(R.id.email);
password = (EditText) findViewById(R.id.password);
sign_in_register = (Button) findViewById(R.id.sign_in_register);

requestQueue = Volley.newRequestQueue(this);

sign_in_register.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {

request = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
Toast.makeText(getApplicationContext(),"SUCCESS "+jsonObject.getString("success"),Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(),Welcome.class));
}else {
Toast.makeText(getApplicationContext(), "Error" +jsonObject.getString("error"), Toast.LENGTH_SHORT).show();

} catch (JSONException e) {

}, new Response.ErrorListener() {

public void onErrorResponse(VolleyError error) {
NetworkResponse response = error.networkResponse;
if (error instanceof ServerError && response != null) {
try {
String res = new String(response.data,
HttpHeaderParser.parseCharset(response.headers, "utf-8"));
// Now you can use any deserializer to make sense of data
JSONObject obj = new JSONObject(res);
} catch (UnsupportedEncodingException e1) {
// Couldn't properly decode data to string
} catch (JSONException e2) {
// returned data is not JSONObject?

protected Map<String, String> getParams() throws AuthFailureError {
HashMap<String,String> hashMap = new HashMap<String, String>();

return hashMap;


Here is the screenshot of Postman.


You need to set Content-Type in you request header like the example below. Just @Override getHeaders method.

public Map<String, String> getHeaders() throws AuthFailureError
    Map<String, String> headers = new HashMap<String, String>();
    headers.put("Content-Type", "application/form-data");
    return headers;

In case of header not updating, see this answer here.