Строка POST и ответ в JSONArray

На самом деле я следую многим ответам stackoverflow, связанным с моим вопросом, но ни один из ответов не работает, и я просто отправляю строку, а взамен мне нужен массив json

ПРИМЕЧАНИЕ: когда я запускаю свой скрипт с жестким кодом, это отлично, но в скрипте значение POST показывает null. Вот мой код на Android:

private void getData(){ Bundle extras=getIntent().getExtras(); final String id = extras.getString("value").toString().trim(); JSONObject obj =new JSONObject(); final ProgressDialog loading = ProgressDialog.show(Categories.this, "Please wait...","Fetching data...",false,false); Volley.newRequestQueue(this).add(new JsonRequest<JSONArray>(Request.Method.POST, CATEGORIES_URL, obj.toString(), new Response.Listener<JSONArray>() { @Override public void onResponse(JSONArray response) { loading.dismiss(); showList(response); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { loading.dismiss(); Toast.makeText(getApplicationContext(), "Ooops!,Internet Connection Problem", Toast.LENGTH_LONG).show(); } }) { @Override protected Map<String, String> getParams() throws AuthFailureError { Map<String, String> params = new HashMap<String, String>(); params.put(KEY_ID,id); return super.getParams(); } @Override protected Response<JSONArray> parseNetworkResponse( NetworkResponse response) { try { String jsonString = new String(response.data, HttpHeaderParser .parseCharset(response.headers)); return Response.success(new JSONArray(jsonString), HttpHeaderParser .parseCacheHeaders(response)); } catch (UnsupportedEncodingException e) { return Response.error(new ParseError(e)); } catch (JSONException je) { return Response.error(new ParseError(je)); } } }); // RequestQueue requestQueue = Volley.newRequestQueue(this); // requestQueue.add(jsonArrayRequest); Toast.makeText(Categories.this,id,Toast.LENGTH_LONG ).show(); } 

и на стороне сервера я использую $id=$_POST['id']; но он показывает null, я не знаю, в чем проблема

MY PHP Script:

  <?php require_once('dbConnect.php'); $json = file_get_contents('php://input'); $stripe_json= json_decode($json, TRUE); $ida=$stripe_json->id; $sql= "select title,description,image,price,cid FROM products a where a.cid='".$ida."'"; $res=mysqli_query($con,$sql); $result = array(); while ($row=mysqli_fetch_array($res)){ array_push($result,array('title'=>$row['0'], 'description'=>$row['1'], 'image'=>$row['2'], 'price'=>$row['3'], )); } echo json_encode(($result)); mysqli_close($con); ?> 

Solutions Collecting From Web of "Строка POST и ответ в JSONArray"

Вероятно, для этого вы можете использовать HTTPPost. Вероятно, из-за файлов cookie и просто нужно добавить это:

  CookieManager cookieManager = new CookieManager(); cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL); httpPost.setCookieHandler(cookieManager); 

надеюсь, это поможет !.

После стольких усилий и рекомендаций мой php теперь работает

код:

  <?php require_once('dbConnect.php'); $json = file_get_contents('php://input'); $stripe_json= json_decode($json); $ida=$stripe_json->id; $sql= "select title,description,image,price,cid FROM products a where a.cid='".$ida."'"; $res=mysqli_query($con,$sql); $result = array(); while ($row=mysqli_fetch_array($res)){ array_push($result,array('title'=>$row['0'], 'description'=>$row['1'], 'image'=>$row['2'], 'price'=>$row['3'], )); } echo json_encode(($result)); mysqli_close($con); ?>