How to send request parameters with same parameter-name

∥☆過路亽.° 提交于 2019-12-23 02:58:09

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/22910880/how-to-send-request-parameters-with-same-parameter-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!