How to post request parameters when using JsonArrayRequest in Volley

后端 未结 5 1495
暗喜
暗喜 2020-12-06 22:03

I am newbie to Json parsing. I am trying to read a json data using JsonArrayRequest but I am little confused in sending parameters and use POST method.In case o

5条回答
  •  天命终不由人
    2020-12-06 22:27

    Here you go..

    final HashMap params = new HashMap();
        params.put("email", userName);
        params.put("password", password);
    
        final JSONObject jsonObject = new JSONObject(params);
    
        JsonArrayRequest req = new JsonArrayRequest(Request.Method.POST, url, jsonObject,
                new Response.Listener() {
                    @Override
                    public void onResponse(JSONArray response) {
                        try {
    //process response
    }
    catch(JSONEXception e){}
    

    And on PHP side you can get these params like this

    $json=file_get_contents('php://input');
    
    $data = json_decode($json);
    $email=$data->{'email'};
    $pass=$data->{'password'};
    

提交回复
热议问题