如何发送具有相同参数名称的请求参数 [英] How to send request parameters with same parameter-name
问题描述
This question is an extension to How do I set params for WS.post() in play 2.1 Java
我的Web服务请求处理程序如下
My web service request handler is as follows
@POST
@Path("/requestPath")
public String addChallengersToLeague(
@FormParam("name") String name,
@FormParam("values") List values);
由于WSRequestHolder在setQueryParameter
方法中接受了Map<String, String>
,所以我无法发送具有相同名称的参数列表.
since WSRequestHolder accepts a Map<String, String>
in setQueryParameter
method, I am not able to send parameter list with same name.
我可以使用名称为值"的多个参数发送来自POSTMAN的请求,并且效果很好.
I can send request from POSTMAN with multiple parameters having name 'values'and it works fine.
您能建议如何使用Play进行相同的操作吗?我正在使用播放2.1.3
Can you suggest how to do the same using play? I am using play 2.1.3
谢谢.
推荐答案
可以使用play.libs.WS.WSRequest API
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();
然后您可以使用response.get().getBody()
获取响应正文.
You can then use response.get().getBody()
to get response body.
这篇关于如何发送具有相同参数名称的请求参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!