Volley And Gson -sending A Post Request Using Jsonobjectrequest
I'm new here and I don't very well speak English, but I do my best to explain me. I have some problems with the Post request. This is my code: private void makeRequest() { Stri
Solution 1:
if you think the problem is with getParams, then with Volley you don't have to use the getParams, it knows how to deal with JSONObject so you can use:
String someurl = URL;
Map<String, Object> jsonParams = newHashMap<>();
jsonParams.put("someparam", getSomeParam());
JsonObjectRequest request = newJsonObjectRequest(Request.Method.POST, someurl, newJSONObject(jsonParams),
newResponse.Listener<JSONObject>()
{
@OverridepublicvoidonResponse(JSONObject response)
{
Log.d(TAG + ": ", "Response: " + response.toString());
//do other stuff
}
},
newResponse.ErrorListener()
{
@OverridepublicvoidonErrorResponse(VolleyError error)
{
if (null != error.networkResponse)
{
Log.d(TAG + ": ", "Error Response code: " + error.networkResponse.statusCode);
}
}
});
requestQueue.add(request);
Also - make sure the variable names in Usuario class match the names you get back in your Json, if it doesn't match the variable in Usuario will be NULL by default.
Post a Comment for "Volley And Gson -sending A Post Request Using Jsonobjectrequest"