S.Hossein Emadi S.Hossein Emadi -4 years ago 108
Android Question

get and post method in android volley request

I'm confused about post and get request in android volley.
can you explain me their differences?
And can I use post method with no Param to get a JSON from URL?

Answer Source

Their difference is in functions defined in server.

In simple words, With a GET method, you are sending your data via the URL. While, with A POST method, data is embedded in the form object and sent directly from your browser to the server. ... We usually use GET to identify and dynamically render pages and POST to send form data but it's not always the case.

and answer of your second question is yes you can but that's not a good idea get would be better for that. here is a example of how you can send requests using Volley Library

StringRequest request = new StringRequest(Request.Method.POST, "www.example.com", new Response.Listener<String>() {
    @Override
    public void onResponse(String response) {

    }
}, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {

    }
}) {
    @Override
    protected Map<String, String> getParams() {
        Map<String, String> parameters = new HashMap<>();
        return parameters;
    }

    @Override
    public String getBodyContentType() {
        return "application/x-www-form-urlencoded; charset=UTF-8";
    }
};
AppController.getInstance().addToRequestQueue(request, tag);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download