In my application I have to send POST request with JSON req param, I tried to create request with Postman Rest Client and it is working fine but not working with below code.
This is the working code, you can try. we can use JsonObjectRequest for raw data. Here i have just showing how to make requestObject that is added in queue
String url = MConstant.API_END+"/userLogin";
Map params = new HashMap();
params.put("email",mEmailView.getText().toString());
params.put("password",mPasswordView.getText().toString());
params.put("api",MConstant.API);
JSONObject objRegData = new JSONObject(params);
JsonObjectRequest jsObjRequest = new JsonObjectRequest
(Request.Method.POST, url, objRegData, new Response.Listener() {
@Override
public void onResponse(JSONObject response) {
try {
// handle response data
} catch (JSONException e) {
e.printStackTrace();
//pDialog.show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
pDialog.hide();
}
})
{
@Override
public Map getHeaders() throws AuthFailureError {
Map params = new HashMap();
params.put("Content-Type", "application/json");
return params;
}
};
in server side PHP we can get data using
$json = file_get_contents('php://input');
$myPostData = json_decode($json, true);