Запрос строки Volley не работает в kotlin! !
Hi guys I'm stuck with this problem for a couple of weeks now, I hope u can help me with that. So I have a local server with database(PHPMyadmin + MySQL), I have a request that I call as follows http://localhost/WebApi/v1/?op=addBars with Postman I pass 4 values with this request first_name, Last_name, Email and Pass and they will be saved in then database and it works fine. but when I try to send data to database with Volley in Kotlin: I don;t get any answer and no error as well so this how my V1.php looks like
case 'addBars': if(isset($_POST['Email']) && isset($_POST['Pass']) && isset($_POST['First_Name'])&& isset($_POST['Last_Name'])){ $db = new DbOperation(); if($db->createBars($_POST['Email'], $_POST['Pass'],$_POST['First_Name'], $_POST['Last_Name'])){ $response['error'] = false; $response['message'] = 'Bars added successfully'; }else{ $response['error'] = true; $response['message'] = 'Could not add Bars'; } }else{ $response['error'] = true; $response['message'] = 'Required Parameters are missing'; } break;
это также то, как выглядят бары создания в DbOperation.php
public function createBars($Email,$Pass,$First_Name,$Last_Name){ $stmt = $this->con->prepare("INSERT INTO Bars (Email, Pass,First_Name,Last_Name) VALUES (?,?,?,?)"); $stmt->bind_param("ssss", $Email, $Pass,$First_Name,$Last_Name); if($stmt->execute()) return true; return false; }
Именно так я использую запрос Volley в Kotlin
val stringRequest = object : StringRequest(Request.Method.POST, EndPoints.URL_ADD_Bars, Response.Listener { response -> try { val obj = (response) Toast.makeText(applicationContext ,"test "+obj+"" , Toast.LENGTH_SHORT).show() // Toast.makeText(applicationContext, obj.getString("message"), Toast.LENGTH_LONG).show() } catch (e: JSONException) { Toast.makeText(applicationContext, "response,"+response.toString()+"", Toast.LENGTH_LONG).show() e.printStackTrace() } }, object : Response.ErrorListener { override fun onErrorResponse(volleyError: VolleyError) { Toast.makeText(applicationContext, "error,"+volleyError.toString()+"", Toast.LENGTH_LONG).show() } }) { @Throws(AuthFailureError::class) override fun getParams(): Map<String, String> { val params = HashMap<String, String>() params.put("Email",Email) params.put("Pass",Pass) params.put("First_Name",First_Name) params.put("Last_Name",Last_Name) return params } } //adding request to queue VolleySingleton.instance?.addToRequestQueue(stringRequest)}
и вот как выглядят мои конечные точки
object EndPoints { private val URL_ROOT = "https://192.130.180.209/WebApi/v1/?op=" val URL_ADD_Bars = URL_ROOT + "addBars" val URL_GET_Bars = URL_ROOT + "getBars" val URL_Bars_info = URL_ROOT + "Bars_info" val URL_Bars_Listing = URL_ROOT + "Bars_Listing" val URL_Bars_Listing_name_adress = URL_ROOT + "Bars_Listing_name_adress" val URL_Bars_info_update_api = URL_ROOT + "Bars_info_update_api" }
Что я уже пробовал:
I will be so grateful if u can help me with that :) and I f u have any questions just hit me up I'm using volley:1.1.0 compileSdkVersion 29 buildToolsVersion "29.0.3"