PDA

View Full Version : ارسال متد POST با Volley



alibakhshi025
چهارشنبه 19 دی 1397, 14:35 عصر
سلام
دوستان چرا پارامتری POST با JsonObjectRequest ارسال نمیشه کد زیر



Map<String, String> params = new HashMap<String, String>();
params.put("name", "test");

JSONObject jsonObj = new JSONObject(params);
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest
(Request.Method.GET, URL, jsonObj, new Response.Listener<JSONObject>() {

@Override
public void onResponse(JSONObject response) {

Toast.makeText(MainActivity.this,response.toString (),Toast.LENGTH_LONG).show();


}
}, new Response.ErrorListener() {

@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this, error.toString(), Toast.LENGTH_LONG).show();
}
});
requestQueue.add(jsonObjectRequest);


کد سمت سرور هم اینه


header('Content-Type: application/json');


$_POST = json_decode(file_get_contents('php://input'), true);


$response = array();
$response['name'] = $_POST['ali'];
echo json_encode($response);


با StringRequest نوشتم بدون مشکل اجرا میشد و ارسال میکرد

mohammad_alikhani
چهارشنبه 26 دی 1397, 07:50 صبح
سلام
به خاطر اینکه پارامتر رو به جای POST نوشتی GET.

Request.Method.GET رو عوض کن به Request.Method.POST