[英]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.