POST request with JSON body in Volley Android

前端 未结 1 1424
名媛妹妹
名媛妹妹 2021-01-16 17:19

I am using volley library. I have the following API url http://example.com/project/contriller/ and need to post the json request as body {\"function\":\"getList\",\"pa

相关标签:
1条回答
  • 2021-01-16 17:57

    Please check below two options for that.

    Option1

    Try to send data in Map variable as below, and put this code just above you are calling request using Post as below.

            Map<String, String> postParam= new HashMap<String, String>();
            postParam.put("function", "getList");
            postParam.put("latitude", "10.0086575");
            postParam.put("token", "");
    
            new JsonObjectRequest(url, postParam, new Response.Listener<JSONObject>() { ... });
    

    option2

    You can use below to send direct JSON.

            final JSONObject jsonData = new JSONObject("{\"function\":\"getList\",\"parameters\":{\"latitude\":\"10.0086575\",\"longitude\":\"76.3187739\"},\"token\":\"\"}");
    
            new JsonObjectRequest(url, jsonData, new Response.Listener<JSONObject>() { ... });
    
    0 讨论(0)
提交回复
热议问题