0

Im trying to do a POST request to a page the parameters needed for the request have to be in a json because they are in this format:

{
   a: 1,
   b: "ASD",
   c: ["A","B"]
}

which as far as i know this cant be turned to a Map<String, String> object, which is needed in order to make a StringRequest instead of a JsonObjectRequest, with that being said is there any way to send a jsonObject as parameter and still be able to handle a string response from the server (Using volley)?

I have read these questions already:

How to handle string response from php using android volley JsonObjectRequest [com.android.volley.ParseError: org.json.JSONException]?

-This one didn't get a functioning answer

How to get string response from php using android volley JsonObjectRequest?

-This one doesn't answer my question

Volley - POST/GET parameters

-This one has a promising answer with custom requests, but it does the opposite of what im attempting and i was unsuccessful at creating my own custom request that accepted the params i needed.

ivan
  • 1,177
  • 8
  • 23

1 Answers1

1

Turns out that posting something like a[0]:"1" and a[1]:"2" in the hashmap params is the same as doing a: ["1","2"] so im fine using StringRequest since it uses a <String,String> Map for parameters, that being said i ended up using this:

StringRequest xx = new StringRequest(Request.Method.POST, getAjaxUrlForFunction("Login"), new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Log.w("RESPONSE",response);
                callback.onSucces(response);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                error.printStackTrace();
                callback.onError(error);
            }
        }){
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String,String> paramss = new HashMap<String, String>();
                paramss.put("funcion","login");
                paramss.put("ajax_request","controller");
                paramss.put("args[0]", name);
                paramss.put("args[1]", password);
                return paramss;
            }
        };
ivan
  • 1,177
  • 8
  • 23