How @PUT some value in webservice via retrofit

I want to send a list of integers with userName and password to WebService, something like the following request

UpdateDocumentState(List<int> documentIds, string userName, string password)

      

But I don't know how to do it? Use @Post or @Put? use @Query or @Field? I googled but didn't find a good example or tutorial that explained them well. (All tutorials I found were about @GET)

can someone give me a piece of code how to do this?

+3


source to share


1 answer


About using @PUT or @POST I think you needed to get this information from the WebService developers.

Anyway, here's a sample code for both retrofit annotations with or without a response.

@POST("your_endpoint")
void postObject(@Body Object object, Callback<Response> callback);

@PUT("/{path}") 
String foo(@Path("path") String thePath);

      

EDIT: Object is a custom class that represents the data you had to send to the WebService.

public class DataToSend {
  public List<Int> myList;
  public String username;
  public String password;
}

      



For example, when declaring the @POST annotation would be:

@POST
void postList(@Body DataToSend dataToSend, Callback<Response> callback);

      

and then you call the method using Retrofit service

yourService.postList(myDataToSend, postCallback);

      

+4


source







All Articles