Google Volley ignores POST-Parameter

前端 未结 5 1033
情书的邮戳
情书的邮戳 2020-12-18 08:32

I\'m currently trying to send a simple POST-request via Google Volley to my server. Therefore I\'ve written the following lines of code:

Map

        
5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-18 09:10

    Woking example with the issue that Rajesh Batth mentioned

    Java code:

        JSONObject obj = new JSONObject();
        try {
            obj.put("id", "1");
            obj.put("name", "myname");
        } catch (JSONException e) {
            e.printStackTrace();
        }
    
        JsonObjectRequest jsObjRequest = new JsonObjectRequest(
                Request.Method.POST, url, obj, listener, errorlistener);
    
        RequestQueue queue = Volley.newRequestQueue(context);
        queue.add(jsObjRequest);
    

    PHP-Code:

        $body = file_get_contents('php://input');
        $postvars = json_decode($body, true);
        $id = $postvars["id"];
        $name = $postvars["name"];
    

    Note:

    The PHP-Vars $_POST and $_REQUEST and $_GET are empty if you are not sending additional GET-VARS.

提交回复
热议问题