简体   繁体   English

如何使用 Android 中的 Kotlin 发出 POST 请求并将数据发送到 API?

[英]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.我是新手android用户,请帮我实现向API发送消息。 I have a POST request:我有一个 POST 请求:

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我已经阅读了教程,但我不知道如何为我的应用程序做这件事

For network call in Android, you can use Retrofit and Volley Library.对于 Android 中的网络调用,可以使用 Retrofit 和 Volley 库。 Both are good and easy to understand.两者都很好且易于理解。

Some reference: Make HTTPS request using Retrofit一些参考: Make HTTPS request using Retrofit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM