I want to make a GET request using Volley in Android Studio and in this request I want to include a body.
The problem is that when using the GET request, the body in the server is None
(I am using Flask). On the other side, when using the POST method, the body reaches the server correctly. This is my code:
RequestQueue queue = Volley.newRequestQueue(getApplicationContext());
String url = Globals.WINGS_VEHICLES_URL;
JSONObject payload = new JSONObject();
try {
payload.put("user_id", Globals.USER_ID);
} catch (JSONException e) {
e.printStackTrace();
}
final String requestBody = payload.toString();
System.out.println(requestBody);
StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
System.out.println(response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
}){
@Override
public String getBodyContentType() {
return "application/json";
}
@Override
public byte[] getBody() {
return requestBody.getBytes();
}
};
stringRequest.setRetryPolicy(new DefaultRetryPolicy(0, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
queue.add(stringRequest);
Is this a Volley restriction, or am I doing something wrong? Assume that I am using a JSONObject
as body, non empty.