Pergunta

This question is an extension to How do I set params for WS.post() in play 2.1 Java

My web service request handler is as follows

@POST
@Path("/requestPath")
public String addChallengersToLeague(
                    @FormParam("name") String name,
                    @FormParam("values") List values);

since WSRequestHolder accepts a Map<String, String> in setQueryParameter method, I am not able to send parameter list with same name.

I can send request from POSTMAN with multiple parameters having name 'values'and it works fine.

Can you suggest how to do the same using play? I am using play 2.1.3

Thanks in advance.

Foi útil?

Solução

This can be done using play.libs.WS.WSRequest API

Following is a simple example

WSRequest request = new WSRequest("<Method>"); //Method can be GET, POST etc
request.setUrl("<service-url>");
request.setHeader("Content-Type", "application/x-www-form-urlencoded");

com.ning.http.client.FluentStringsMap map = new com.ning.http.client.FluentStringsMap();

map.add("name", "aniket");

Set<String> values= new HashSet<String>();
values.add("1");
values.add("2");
values.add("3");
values.add("4");

map.add("values", values);

request.setQueryParameters(map);

Promise<Response> response = request.execute();

You can then use response.get().getBody() to get response body.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top