'Why I cannot send parameters along with POST request on android to flask backend using volley?

Hello There I was working on android application using flask as backend to access sqlite database and using Volley Library for communication between the app and the local server it is working on my other methods but it stopped to send the parameters in one of the new methods I created.

The method

private List<String> batch_fetcher(String program) {

List<String> batch = new ArrayList<>();

JsonObjectRequest jsonObjectRequest = new JsonObjectRequest
(Request.Method.POST, Constants.BAT_SELECT_URL, null, new Response.Listener<JSONObject>() {

                    @Override
                    public void onResponse(JSONObject response) {
                        try {
                            JSONArray jArray = response.getJSONArray("batchlist");
                            for (int i = 0; i < jArray.length(); i++) {
                                batch.add(jArray.getString(i));
                                System.out.println(jArray.getString(i));
                            }
                        } catch (JSONException jSONException) {
                            jSONException.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
    
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Toast.makeText(Selector_activity_taker.this, error.getMessage(), Toast.LENGTH_SHORT).show();
                    }
    
                }){
            @Override
            protected Map<String,String> getParams(){
                Map<String,String> params = new HashMap<String, String>();
                params.put("selected",program);
                return params;
            }
    
        };
    
        MySingleton.getInstance(this).addToRequestQueue(jsonObjectRequest);
    
        return batch;
    }

Python code for flask

@app.route('/batselect', methods=['POST'])
def bat_fetch():
    if request.method == 'POST':
        prog_sel = request.form.get('selected')
        print(f"The received one is {prog_sel} ") 
        response['batchlist'] = dbop.get_batch(prog_sel)
    data = json.dumps(response)
    return data

I tried running the code with hardcoded parameter as

@app.route('/batselect', methods=\['POST'\])
def bat_fetch():
    if request.method == 'POST':
        prog_sel = request.form.get('selected')  
        response['batchlist'] = dbop.get_batch('Regular')
    data = json.dumps(response)
    return data

and It returned the required data to the android app.

I also tried getting the type of the prog_select and it is NoneType. Thank you



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source