web-services - 如何在 REST Web 服务中放置多个查询参数

标签 web-services rest curl jax-rs query-parameters

有谁知道如何在 REST web 服务中放置多个查询参数?
我已经使用 java.My curl 示例编写如下:

curl -X PUT http://localhost:8080/project/resources/user/directory/sub-directory?name=shareuser&type=Read -v

我的程序是:
@PUT
@Path("{user}/{directory:.+}")
public Response doshare(@PathParam("user")String name,
        @PathParam("directory")String dir,
        @QueryParam("name")String sharename,
        @QueryParam("type")String type){
    mongoDAOImpl impl=new mongoDAOImpl();
    Mongo mongo=impl.getConnection("127.0.0.1","27017");
    DB db=impl.getDataBase(mongo,"public");
    DBCollection coll=impl.getColl(db,name);
    DBCollection coll2=impl.getColl(db,"sharedb");
    shareDTO sharedto=new shareDTO();
    String authority=type.toLowerCase();
    if(authority.equals("rd")){
        sharedto.setAuthority("4");
    }else if(authority.equals("rw")){
        sharedto.setAuthority("12");
    }
    sharedto.setTargetuser(sharename);
    sharedto.setRealURI("/home/public/"+name+"/"+dir);
    sharedto.setIdentifier(name);
    sharedto.setParentURI("/home/public/"+sharename);
    boolean bool = false;
    sharefun=new sharefunction();
    if(sharefun.checksubfoldershared(coll, coll2, sharedto)){
        bool=sharefun.sharefiles(coll, coll2, sharedto);
    }else{
        System.out.println("Error");
    }
    // ...

但我只得到名称查询参数。如何获取或如何输入 curl 命令以获取所有查询参数?

最佳答案

您的代码很好 - 问题在于您调用 curl 的方式。将包含“&”的 URL 传递给 curl 时,您必须在 URL 周围加上引号。否则,shell 会将 '&' 之后的内容解释为单独的命令。

编辑:当我将其作为评论提交时,我的文本被修改了。您需要执行以下操作:

curl -X PUT 'http://localhost:8080/project/resources/user/directory/sub-directory?name=shareuser&type=Read' -v

关于web-services - 如何在 REST Web 服务中放置多个查询参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5785610/

相关文章:

c# - 合流休息 API : Can I create a page by space and parent?

php - 当我应该使用 php curl 获取状态 304 时获取 HTTP 状态 200

php - Bigcommerce API 博客文章

javascript - 关于 cookie 爬虫的想法?

spring - 使用 Spring RestTemplate 绕过主机验证访问 HTTPS Rest api

java - 调试 Web 服务请求

Java - 公开一个将接口(interface)实现为 Web 服务的 DAO 类

C# 无法将 cookiecontainer 分配给 asmx web 服务客户端

java - 如何在 JAVA 中进行 REST Web 服务调用?

swift - 使用 vapor 3 在同一条路线上处理不同种类的 json