Home > Blockchain >  how to POST parameters to server using retrofit2?
how to POST parameters to server using retrofit2?

Time:12-14

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

CodePudding user response:

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

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