Search code examples
androidapikotlinretrofitretrofit2

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


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
        )
    }