0

Hi i using volley connection in my Android project, i want to connect to rest api. If i using curl the code is

curl -G -H "Content-type:application/json" -d "q={\"order_by\":[{\"field\":\"dates\",\"direction\":\"desc\"}]}" http://testurl/api/v1/test

And i do my volley connection like this

String x = "{\"order_by\":[{\"field\":\"dates\",\"direction\":\"desc\"}]}";
 JSONObject jo;
try{
    jo = new JSONObject(x);
    JsonObjectRequest jreq = new JsonObjectRequest(Method.GET,
                             "http://testurl/api/v1/test", 
                    jo, new Response.Listener<JSONObject>(){                                @Override
                            public void onResponse(JSONObject response) {
                                try{Log.i("response",response.toString(3));}
                                catch(JSONException 
                        },
                        new Response.ErrorListener() {@Override
                            public void onErrorResponse(VolleyError error) {

                            }
                        });
                queue.add(jreq);
    }
    catch(JSONException e){}

connection success but result is not right, i guest because in in api must use q=JSON_SEARCH and in my volley connection i can't put q= in there..

Have anyone have some suggestion for my problem ?

user1752973
  • 127
  • 3
  • 10

1 Answers1

0

Good hint is to trace the connection with wireshark, so that you can exactly see the difference. There should be probably used headers in request. Something like here How to set custom header in Volley Request

Community
  • 1
  • 1
maxxxo
  • 672
  • 3
  • 10
  • 28