0

I have to send a request to an API call which takes data at :

https://www.example.com/abc/abc/Register.php

It takes POST data such as mobile = 1234567989 and id = 12345 in Postmen the data goes in the body as form-data or x-www-form-urlencoded with keys and values.

How do I do that in android studio using kotlin?

Dhaval Solanki
  • 4,589
  • 1
  • 23
  • 39
Kendade
  • 15
  • 3
  • 1
    Possible duplicate of [HTTP Request in Kotlin](https://stackoverflow.com/questions/46177133/http-request-in-kotlin) – Andra Nov 21 '19 at 06:14

1 Answers1

0

Use retorfit library.Fast and easy

   interface YourApi {
    @POST("/examaples")
    fun getExamples(@Body requestObject:JsonObject): Call<JsonOBject>
 }

Your request body

val requestObject = JsonObject()
requestObject.addProperty("param1","value")

Send parameter

api.getExamples(requestObject).enqueue(object : Callback<JsonObject> {
        override fun onFailure(call: Call<JsonObject>, t: Throwable) {
            t.message
        }

        override fun onResponse(call: Call<JsonObject>, response: Response<JsonObject>) {
            if (response.isSuccessful){
                val resp = response.body()
            }
        }

    })
Aqsin
  • 23
  • 3