1. Are you ready for the Galaxy S20? Here is everything we know so far!

can't post parameter to JSONObjRequest

Discussion in 'Android Apps & Games' started by RameshbabuK, Sep 25, 2014.

  1. RameshbabuK

    RameshbabuK Newbie
    Thread Starter

    Hi,

    Am working with volley web service. I want to post some values to

    web service using JSONObjRequest in volley. But got error like

    com.android.volley.servererror.


    Kindly check given below code details.

    RequestQueue aQueue=Volley.newRequestQueue(getApplicationContext());

    try
    {
    obj.put("username","abc@gamil.com");
    obj.put("password","demo");
    }
    catch(Exception e)
    {
    System.out.println(e.getMessage());
    }

    final ProgressDialog pDialog = new ProgressDialog(this);
    pDialog.setMessage("Loading...");
    pDialog.show();

    Map<String, String> jsonParams = new HashMap<String, String>();
    jsonParams.put("username", "demo@tracme.co.in");
    jsonParams.put("password", "demo");

    JsonObjectRequest aRequest = new JsonObjectRequest(
    Method.POST,
    "http://20.30.11/trac/Vehicle",
    new JSONObject(jsonParams),

    new Response.Listener<JSONObject>() {
    @Override
    public void onResponse(JSONObject response) {
    Toast.makeText(getApplicationContext(),"Success = " + response, 20000).show();
    pDialog.dismiss();

    }
    },
    new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {

    Toast.makeText(getApplicationContext(),"Error = " + error.toString(), 20000).show();
    pDialog.dismiss();
    }
    })

    {

    @Override
    public Map<String, String> getHeaders() throws AuthFailureError {
    Map<String,String> headers= new HashMap<String, String>();
    //params.put("Content-Type","application/x-www-form-urlencoded");
    headers.put("Content-Type", "application/json; charset=utf-8");
    headers.put("User-agent", "My useragent");
    return headers;
    }

    };

    aQueue.add(aRequest);





    So please help me for how to post values to web service using

    JSONObjRequest:eek:.

    Thanks&Regards,
    Ramesh babu.K
     



    1. Download the Forums for Android™ app!


      Download

       
Loading...

Share This Page

Loading...