Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to POST parameters to server using retrofit2?

i want to POST data from android to server side using retrofit2 like :
https://192.168.1.1/image?iname=VAR
and VAR is variable from the user

interface ModelApi {
    @POST("/image")
    suspend fun pushImageToModelFromAPI(
        @Body file: RequestBody,
    )
}

i tried the above code but this doesn’t work

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

For query params you need to use @Query. Like this:

interface ModelApi {
    @POST("/image")
    suspend fun pushImageToModelFromAPI(
        @Body file: RequestBody,
        @Query("iname") name: String
    )
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading