kotlin volley post request
// implementation
implementation 'com.android.volley:volley:1.1.1'
// simple example of Login POST Request using Volley
val username: String = etName.getText().toString()
val password: String = etPass.getText().toString()
val stringRequest: StringRequest = object : StringRequest( Method.POST, url,
Response.Listener { response ->
try {
//Parse your api responce here
val jsonObject = JSONObject(response)
Toast.makeText(this, response, Toast.LENGTH_LONG).show()
} catch (e: JSONException) {
e.printStackTrace()
}
},
Response.ErrorListener { error ->
Toast.makeText(this, error.toString(), Toast.LENGTH_LONG).show()
}) {
override fun getParams(): Map<String, String> {
val params: MutableMap<String, String> = HashMap()
//Change with your post params
params["username"] = username
params["password"] = password
return params
}
}
val requestQueue = Volley.newRequestQueue(this)
requestQueue.add(stringRequest)