Cannot get parameters from PHP when using Volley with JsonObjectRequest

I am using a Volley structure with a JsonObjectRequest request. I use

JsonObjectRequest loginRequest = new JsonObjectRequest(b.toString(), params, new Listener<JSONObject>() {}, new Response.ErrorListener() {}); 

The params variable contains parameters, and this is a JSONObject.

The problem is that I cannot access any of these variables in my PHP code. The $ _POST or $ _REQUEST variables give me nothing.

I also tried something like below, but no luck.

 $data = json_decode(file_get_contents("php://input")); 
+4
source share
1 answer

I ran into the exact same issue when using Volley with my PHP API! It turns out using JSONObject parameters is sent as JSON. Therefore, PHP $ _POST does not recognize it, because it is not in the format: param1 = value1 & param2 = value

To see for yourself, try: print file_get_contents ("php: // input");

I wrote a blog post about this and made a workaround. Instead of using JsonObjectRequest, I created a subclass of the request (section 4)

+7
source

Source: https://habr.com/ru/post/1488189/


All Articles