I am getting this error while making a network request using volley library,I have followed these links Android Volley - BasicNetwork.performRequest: Unexpected response code 400 and Unexpected response code 404 volley but none of them working in my case . Here is my request code
StringRequest stringRequest = new StringRequest(Request.Method.POST,AppConstants.LOG_IN_API , new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("TAG", "Login Response: " + response.toString());
try {
JSONObject jsonObject = new JSONObject(response);
Log.v("USerid",""+jsonObject.getInt("userid"));
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
System.out.println("volley Error ................."+volleyError);
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Log.v("getparams","Is called");
Map<String, String> params = new HashMap<String, String>();
params.put(AppConstants.USER_ID, "[email protected]");
params.put(AppConstants.PASSWORD, "123456");
return params;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json; charset=utf-8");
return headers;
}
};
Log.v("Request",""+stringRequest);
AppController.getInstance().addToRequestQueue(stringRequest);
}
Is there anyone who can tell me where I am doing wrong in my code? Any help is appreciable.
Generally this response is caused by sending wrong parameters with the URL. Please check every parameter with spelling and make sure if response is obtained in string or in object. Also check Content-type.
Hope this will help you.
Thank you.
If GET is working and POST is not, and you get 404 response it means that your post request can't be routed by the server. I had the same problem and the solution was simple. I've made my server in NodeJS and I didn't handle POST action for my URL. I was testing it with get and everything was fine.
My test method on node server with Express was:
app.get('/data/helloWorld', routeData.helloWorld);
And of course I should add a route for post method.
app.post('/data/helloWorld', routeData.helloWorld);
By mistake I had put GET request instead of POST, I changed it and that solved my issue of 404 response.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With