0

如何在下面向此服务发出 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);
        }

  }

}

我正在使用这个:

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'

我关心的是如何将 Set 作为 QueryParam 传递。是否可以使用传递的 http 数据发出 GET 请求?

感谢您的帮助。

4

1 回答 1

3

您将查询参数作为路径参数传递。正确的 curl 调用是:

http://localhost:8080/__services/v2/rest/recommendation/trendingcontent/home?max=3&containerType=2020&containerID=1&contentTypes=1100

如果您需要不止一种contentTypes用途:

http://localhost:8080/__services/v2/rest/recommendation/trendingcontent/home?max=3&containerType=2020&containerID=1&contentTypes=1100&contentTypes=22340&contentTypes=43000
于 2013-11-08T08:44:24.087 回答