Search code examples
androidkotlinretrofitretrofit2

How to make a POST request and send data to API using Kotlin in Android?


I am a novice android user, please help me to implement sending a message to the API. I have a POST request:

curl --location --request POST 'https://api.admin.ragos.net/api/external/prints ' \
--header 'Content-Type: application/json' \
--data-raw '{
    "body": "text text text"
}'

I have a string that I have to send to this address, how do I implement it in my application when I click on the button in the activity? I've read the tutorials but I can't figure out how to do it for my app


Solution

  • For network call in Android, you can use Retrofit and Volley Library. Both are good and easy to understand.

    Some reference: Make HTTPS request using Retrofit