Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to PUT multiple query parameter in REST web service

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

My program is :

@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");
    }
    // ...

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?

like image 582
sudo Avatar asked Apr 26 '11 03:04

sudo


People also ask

How can URL have multiple query parameters?

Any word after the question mark (?) in a URL is considered to be a parameter which can hold values. The value for the corresponding parameter is given after the symbol "equals" (=). Multiple parameters can be passed through the URL by separating them with multiple "&".


1 Answers

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.

EDIT: 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
like image 54
Mike Baranczak Avatar answered Sep 28 '22 06:09

Mike Baranczak