[英]Passing java.util.Set as QueryParam value in a GET request
How do I make a GET request to this service below: 我如何在下面向此服务发出GET请求:
public class MyService {
@GET
@Path("/trendingcontent/home")
Map<String, Object> getTrendingContentHome(@QueryParam("max") @DefaultValue("5") int max,
@QueryParam("containerType") @DefaultValue("-1") int containerType,
@QueryParam("containerID") @DefaultValue("-1") long containerID,
@QueryParam("contentTypes") Set<Integer> objectTypes) {
if (recommendationManager.isEnabled()) {
EntityDescriptor descriptor = null;
if (containerType > 0 && containerID > 0) {
// only set the descriptor if the container is not root
Community root = communityManager.getRootCommunity();
if (containerType != root.getObjectType() || containerID != root.getID()) {
descriptor = new EntityDescriptor(containerType, containerID);
}
}
RecommendationQuery query;
if (objectTypes == null || objectTypes.isEmpty()) {
objectTypes = recommendationQueryHelper.getContainableTypes();
}
if (descriptor == null) {
query = recommendationQueryHelper.getSystemTrendingContent(objectTypes);
}
else {
query = recommendationQueryHelper.getContainerTrendingContent(objectTypes, Sets.newHashSet(descriptor));
}
return getRecommendationResponse(query, max, home);
}
else {
return getPopularContent(max, home);
}
}
}
I'm using this: 我正在使用这个:
curl 'http://localhost:8080/__services/v2/rest/recommendation/trendingcontent/home/3/2020/1/1100' -H 'Host: localhost:8080' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Accept-Language: en-US,en;q=0.5' -H 'Accept-Encoding: gzip, deflate' -H 'X-J-Token: 6430c792bc77967ce8c7' -H 'X-Requested-With: XMLHttpRequest'
My concern is how do I pass a Set as QueryParam. 我关心的是如何传递Set作为QueryParam。 Is it possible to make a GET request with http data passed along?
是否可以通过传递的http数据进行GET请求?
Thanks for helping out. 感谢您的帮助。
You pass query parameters as path parameters. 您将查询参数作为路径参数传递。 The correct curl call is:
正确的curl调用是:
http://localhost:8080/__services/v2/rest/recommendation/trendingcontent/home?max=3&containerType=2020&containerID=1&contentTypes=1100
If you need more than one contentTypes
use: 如果您需要多个
contentTypes
使用:
http://localhost:8080/__services/v2/rest/recommendation/trendingcontent/home?max=3&containerType=2020&containerID=1&contentTypes=1100&contentTypes=22340&contentTypes=43000
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.