Post Request With Volley
I'm making a basic mobile app to interact with a nosql database. So far, I've had no problems using Volley. I have two main entities in my database, and both are storing all of t
Solution 1:
Try a different syntax and Request type for your case:
Map<String, Object> jsonParams = newArrayMap<>();
jsonParams.put("nodeId", null);
jsonParams.put("userId", null);
jsonParams.put("email", "some@gmail.com");
jsonParams.put("userProfile", null);
jsonParams.put("region", null);
jsonParams.put("password", 123);
jsonParams.put("places", newArrayList());
JsonObjectRequest request = newJsonObjectRequest(Request.Method.POST, url, newJSONObject(jsonParams),
newResponse.Listener<JSONObject>()
{
@OverridepublicvoidonResponse(JSONObject response)
{
//print it here and check
}
},
newResponse.ErrorListener()
{
@OverridepublicvoidonErrorResponse(VolleyError error)
{
if (null != error.networkResponse)
{
//do whatever
}
}
});
Solution 2:
I found the error. It ended up not having anything to do with the Volley code itself; what I had was actually working. The problem was that I had forgotten that I commented out some of the input verification code, and in doing so, it wasn't picking up the text from those two fields.
Earlier on in the project, I had input verification set up so that users couldn't submit invalid characters. I didn't have that set up for the date fields, so I commented some of that code out.....including the lines that were calling the getText().toString() method for each field. So it literally was never pulling in the input from those fields. It's so obvious in retrospect....... :(
startdate = startDateEditText.getText().toString();
System.out.println(startdate);
if (!isValidDate(startdate)) {
startDateEditText.setError("Invalid input.");
isValidInput = false;
}
enddate = endDateEditText.getText().toString();
System.out.println(enddate);
if (!isValidDate(enddate)) {
endDateEditText.setError("Invalid input.");
isValidInput = false;
}
if (isValidInput) {
newPostRequest();
finish();
}
}
});
Post a Comment for "Post Request With Volley"