Skip to content

Instantly share code, notes, and snippets.

@ibrahim4851
Created May 22, 2021 12:31
Show Gist options
  • Save ibrahim4851/6b12d65efbdffb2b6dc67f5510f08238 to your computer and use it in GitHub Desktop.
Save ibrahim4851/6b12d65efbdffb2b6dc67f5510f08238 to your computer and use it in GitHub Desktop.
PostObject
fun postString(context: Context?) {
val queue = Volley.newRequestQueue(context)
val sr: StringRequest = object : StringRequest(
Method.POST, "http://favor4u.xyz/calisma/samplepost.php",
Response.Listener { response ->
val res = JSONObject(response)
val value = res.getString("value")
Toast.makeText(context, "Successful", Toast.LENGTH_SHORT).show()
Log.i("value", value)
}, Response.ErrorListener { error ->
Toast.makeText(context, "Error", Toast.LENGTH_SHORT).show()
}) {
override fun getParams(): Map<String, String> {
val params: MutableMap<String, String> = HashMap()
params["value"] = "value"
return params
}
@Throws(AuthFailureError::class)
override fun getHeaders(): Map<String, String> {
val params: MutableMap<String, String> = HashMap()
params["Content-Type"] = "application/x-www-form-urlencoded"
return params
}
}
queue.add(sr)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment