I'm trying to get a php file to receive data from a JSONObject by POST request.
This is my android code in Kotlin:
val jsonObject = JSONObject().apply {
put("username", username)
put("password", password)
put("value", value)
put("time", time)
}
val jsonObjectReq = JsonObjectRequest(Method.POST, url, jsonObject,
Response.Listener { response ->
Toast.makeText(this, response.getString("message"), Toast.LENGTH_LONG).show()
},
Response.ErrorListener {
Toast.makeText(this, "Error", Toast.LENGTH_LONG).show()
})
Volley.newRequestQueue(this).add(jsonObjectReq)
I thought that in a php script, $_POST["username"] would get the username I put in the json object, but it doesn't. In fact the php script gets no post variables with my from the JsonObjectRequest. How do I get the values I put in the JSONObject in my php script and if I can't then what is the purpose of putting jsonObject in the constructor call for JSONObjectRequest?