I am working on a get request implementation using Volley in an android application that communicates with a node backend server to pull user details for a profile page.
I have a method using Volley which sends the get request to the node backend. I can see that I get back the result I am looking for for the user details on the node end, but then somehow, the onResponse method is never called and my response is null. I think I am missing something on either how I send the response or on the Volley side but can't seem to fix it. The onErrorResponse codeblock is also never hit, I just get a null return. I will post the volley and node code below:
Volley
public Map<String, String> makeVolleyGetRequest(Context context, String url, String token) {
final Context applicationContext = context;
String getUrl = url + "/token=" + token;
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, getUrl, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d("Response", response.toString());
try {
responseEntries.put("email", response.getString("email"));
responseEntries.put("firstName", response.getString("firstName"));
responseEntries.put("lastName", response.getString("lastName"));
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("Error: ", error.getMessage());
}
});
RequestQueue requestQueue = Volley.newRequestQueue(applicationContext);
request.setRetryPolicy(new DefaultRetryPolicy(0, -1, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
requestQueue.add(request);
return responseEntries;
}
Node server code:
app.get('/getUserDetails/token=:token', function (req, res) {
var url = req.url;
var token = url.split("=");
var parsedToken = token[1];
console.log("Request token is " + parsedToken);
retrieveUser.retrieveUser(parsedToken, function (found) {
console.log("found is " + found);
res.json(found);
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify(found));
console.log("response sent");
});
});
The node side calls a method called retrieveUser, which I can see is returning the correct user from the token provided, so I do not believe there is any issue there.
Any help is greatly appreciated!
via A.Dow
No comments:
Post a Comment