0
Good morning guys, I’m trying to make an integration with web_services of a partner, by php everything worked correctly now I want to implement directly on Android using Volley but I’m getting authentication error, follows below my code:
RequestQueue rq = Volley.newRequestQueue(MainActivity.this);
String url = url;
JsonObjectRequest jReq = new JsonObjectRequest(Request.Method.GET, url,null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject jsonObject2) {
try {
if (jsonObject2 != null) {
lista.add(jsonObject2.toString());
adapter.notifyDataSetChanged();
} else {
Log.i("MaintActivity", jsonObject2.toString());
}
} catch (Exception e) {
Log.i("MaintActivity", e.getMessage().toString());
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
if (volleyError != null) {
Log.i("MaintActivity", volleyError.getMessage().toString());
}
}
}) {
@Override
protected Map<String,String> getParams(){
Map<String,String> params = new HashMap<String, String>();
params.put("ws_key",ws_key);
params.put("ws_user",ws_user);
params.put("username",username);
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;
}
};
jReq.setRetryPolicy(new DefaultRetryPolicy(
5000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT
)
);
rq.add(jReq);
It should be noted that debugging, the code is only entering the getHeaders method and does not go through getParams, someone has an idea?
Thanks.
Can post the error?
– Igor Mello
Igor, actually the error is returned by the client web_service, returns me a json : {"result":false,"error_message":"Authentication error!" } I don’t have code errors, build errors etc.... is an authentication error.. that is, the data of key, user and username are not arriving in the web service seems. As I said at the end, debug doesn’t go through the getParams function so it doesn’t seem to include the data in the request.
– Marcelo López