I use Volley with Java not have any problem. put when convert to kotlin i found some problem with send parameter with request I try used custom request class extends from Request this is not fix my problem also i used JsonObjectRequest with hash map some mistake the parameter not send with request. also used JsonObjectRequest with JSONObject also same mistake is still after that i used Post Man API the side from API is fine not has any problem also when used StringRequest not has any problem
my first code with JsonObjectRequest is
val url = "http://10.0.2.2/machine_project/includeJSON/system_machine.php"
val ahOBJ = JSONObject()
ahOBJ.put("dd", 2)
Log.d("TAG","kotJson")
val queu = Volley.newRequestQueue(this)
val ahReq = JsonObjectRequest(Request.Method.POST, url, ahOBJ, Response.Listener { response ->
val str = response.toString()
Log.d("TAG","response: $str")
}, Response.ErrorListener {
error ->
Log.d("TAG","response: ${error.message}")
})
queu.add(ahReq)
the second code is
val jr:RequestQueue = Volley.newRequestQueue(this)
val params = HashMap<String,String>()
params["dd"] = "2"
Log.d("TAGTest", "Ready to go")
val jsObj = JsonObjectRequest(Request.Method.POST,
urlUP,
JSONObject(params),
Response.Listener
{
response ->
Log.d("TAGTest", response.toString())
},
Response.ErrorListener {
error ->
Log.d("TAGTest", "error: ${error.message}")
})
jr.add(jsObj)
all result is
{"error":true,"msg":"All filed required"}
this result from back end API
the API is
$response = array();
if($_SERVER['REQUEST_METHOD'] == 'POST'){
if( isset($_POST['dd'])){
require_once ('systemMachineAPI.php');
$result = get_sm();
if($result != NULL){
$response['error'] = false;
$response['msg'] = $result;
}else{
$response['error'] = true;
$response['msg'] = 'We Found Some Mistake';
}
}else{
$response['error'] = true;
$response['msg'] = 'All filed required';
}
}else{
$response['error'] = true;
$response['msg'] = 'Cannot connect to server';
}
if any body can fix this or try use volley with kotlin post prameter please help me