Is it possible to send a json to a web service with volley?

0

I have been reading and everything that appears to me is to receive a response from the server and send data to it by parameters within the URL. What I would like to know is if there is the possibility that from my Android app I send a json to my web service so that it gets it and receives the data, unlike parameters by the URL.

I use volley as a library to manage the response of the web service.

    
asked by denifer santiago fernandez 17.08.2018 в 21:40
source

1 answer

0
url = "http://httpbin.org/post";
StringRequest postRequest = new StringRequest(Request.Method.POST, url, 
    new Response.Listener<String>() 
    {
        @Override
        public void onResponse(String response) {
            // response
            Log.d("Response", response);
        }
    }, 
    new Response.ErrorListener() 
    {
         @Override
         public void onErrorResponse(VolleyError error) {
             // error
             Log.d("Error.Response", response);
       }
    }
) {     
    @Override
    protected Map<String, String> getParams() 
    {  
            Map<String, String>  params = new HashMap<String, String>();  
            params.put("json", "{\"0\":\"valor1\",\"1\":\"valor2\",\"2\":\"valor3\",\"3\":\"valor4\"}");
            params.put("json2", (new JSONObject("{\"0\":\"valor1\",\"1\":\"valor2\",\"2\":\"valor3\",\"3\":\"valor4\"}")).toString());
            return params;  
    }
};

Try that and convert it to an array in the web service that I imagine you have control over; what I mean in the post parameter "json2" is that you could also create a json in the java santaxis and convert to a string

    
answered by 17.08.2018 в 22:37