如何在REST Web服务中PUT多个查询参数 [英] how to PUT multiple query parameter in REST web service

查看:675
本文介绍了如何在REST Web服务中PUT多个查询参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都知道如何在REST Web服务中PUT多个查询参数?
我使用java.My编写curl示例是这样的:

Do anyone know how to PUT multiple query parameter in REST web service? I have write using java.My curl sample is like this:

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命令以获取所有查询参数?

But I only get the name query parameter.How to get or how to type in curl command in order to get all query parameter?

推荐答案

问题是你调用curl的方式。将网址传递到包含&的curl时,您必须在网址上加引号。否则,shell会将'&'之后的内容解释为一个单独的命令。

Your code is fine - the problem is with the way you're invoking curl. When passing a URL to curl that contains a '&', you have to put quotes around the URL. Otherwise, the shell will interpret the stuff after the '&' as a separate command.

编辑:当我将其作为注释提交时,我的文本会变灰。这里是你需要做的:

My text is getting munged when I submit it as a comment. Here's what you need to do:

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

这篇关于如何在REST Web服务中PUT多个查询参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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