Reputation: 1
Two days have passed since I started with this problem. I read all the post relatives to volley and json but no one helped me. And it´s a weird problem. Let me explain it.
I have to send a JSON object to a server. Inside the object, there is an authentication token. it´s a md5 token with temporal and private token. i get the public token from this url : http://casting.haikoservices.com/service/create_token. Really simple, isn´t it? I use this method to obtain it.
public void getTemporalToken() {
temporal_token="";
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET,
url_temporal_token,null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
temporal_token = response.getString("token");
sendData();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(),
"Error: " + e.getMessage(),
Toast.LENGTH_LONG).show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(),
"OnError"+error.getMessage(), Toast.LENGTH_SHORT).show();
}
});
// Adding request to request queue
AppController.getInstance().addToRequestQueue(jsonObjReq);
}
well. I use postman in chrome to verify if the temporal token that I recive works. (i add the private key, encrypt wiht md5 and try with postman). And now weird things start. The token created with this temporal key is not valid but if I use the token from the web page, it works.
Does it have any sense? If someone can help me I would be very grateful.
Upvotes: 0
Views: 651
Reputation: 11
Use this method. I tested this code, it works properly.
Output
05-21 16:56:47.477: E/data(22710): 647b9ee6151f2bc72a2e737c2ac7da61**
public void getTemporalToken() {
RequestQueue queue= Volley.newRequestQueue(getApplicationContext());
String url_temporal_token= "http://casting.haikoservices.com/service/create_token";
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET,url_temporal_token,null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
String temporal_token = response.getString("token");
Log.e("data", temporal_token);
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(),
"Error: " + e.getMessage(),
Toast.LENGTH_LONG).show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), "OnError"+error.getMessage(), Toast.LENGTH_SHORT).show();
}
});
queue.add(jsonObjReq);
// Adding request to request queue
}
Upvotes: 1