如何发送具有相同参数名称的请求参数 [英] How to send request parameters with same parameter-name

查看:305
本文介绍了如何发送具有相同参数名称的请求参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题是

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆