RameshbabuK
Newbie
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
.
Thanks&Regards,
Ramesh babu.K
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
.Thanks&Regards,
Ramesh babu.K