1

I am using this code

StringRequest stringRequest = new StringRequest(Request.Method.POST,
            uploadUrl,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {

                        Log.d("sfhyoutubeghhj",response);


                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                   //loading.dismiss();
                }
            }) {
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String, String> prams = new HashMap<>();
            prams.put("aaaa", "1111");
            prams.put("bbbb", "2222");
            return prams;
        }
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            HashMap<String, String> headers = new HashMap<String, String>();
            headers.put("Content-Type", "application/json; charset=utf-8");
            headers.put("User-agent", "My useragent");
            return headers;
        }
    };
    RequestQueue requestQueuea = Volley.newRequestQueue(this);
    requestQueuea.add(stringRequest);

Request is going to server and response is also coming but its not sending any variable from android either in GET or POST method

and i m just using

print_r($_REQUEST);

at PHP end

Amit Kumar Pawar
  • 3,252
  • 1
  • 20
  • 27

1 Answers1

0

I think there was a problem with Request queue only

working fine with this code @ Ali Azhar's Answer

StringRequest sr = new StringRequest(Request.Method.POST, url , new Response.Listener<String>() {
    @Override
    public void onResponse(String response) {
        Log.d(TAG, response.toString());
    }
}, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {
        VolleyLog.d(TAG, "Error: " + error.getMessage());
        Log.d(TAG, ""+error.getMessage()+","+error.toString());
    }
}){
    @Override
    protected Map<String,String> getParams(){
        Map<String, String> params = new HashMap<String, String>();
        params.put("id", "28");
        params.put("value", "1");

        return params;
    }

    @Override
    public Map<String, String> getHeaders() throws AuthFailureError {
        Map<String,String> headers = new HashMap<String, String>();
        headers.put("Content-Type","application/x-www-form-urlencoded");
        headers.put("abc", "value");
        return headers;
    }
};

    AppController.getInstance().addToRequestQueue(sr);
Amit Kumar Pawar
  • 3,252
  • 1
  • 20
  • 27