繁体   English   中英

Volley Android中带有JSON正文的POST请求

[英]POST request with JSON body in Volley Android

我正在使用排球库。 我有以下API网址http://example.com/project/contriller/ ,需要将JSON请求发布为正文{"function":"getList","parameters":{"latitude":"10.0086575","longitude":"76.3187739"},"token":""}

如何使用Volley发送呢?

请检查以下两个选项。

选项1

尝试按以下方式在Map变量中发送数据,然后将此代码放在您正要使用Post调用请求的上方,如下所示。

        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>() { ... });

选项2

您可以在下面使用直接发送JSON。

        final JSONObject jsonData = new JSONObject("{\"function\":\"getList\",\"parameters\":{\"latitude\":\"10.0086575\",\"longitude\":\"76.3187739\"},\"token\":\"\"}");

        new JsonObjectRequest(url, jsonData, new Response.Listener<JSONObject>() { ... });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM