Send the String [] array through the request body to the web service using Retrofit

I want to use a web service that takes an array of String [] in the body of the web request.

public void fooWebService(@RequestBody String[] ids)

What would be the best way to send a String [] array from my client Androidusing Retrofit? I guess I will need to use annotation @Body.

content-type- application/json.

+4
source share
1 answer

The default serial modification for retrofitting is JSON, so this will basically work ready. You can use either String[], or List<String>on the client (I prefer the latter).

@POST("/endpoint")
void sendIds(@Body List<String> ids);

RestAdapter .

service.sendIds(ids);
// .. or ..
service.sendIds(Arrays.asList("foo", "bar"));
+3

Source: https://habr.com/ru/post/1536619/


All Articles