开发者

What is the recommended way to set GET parameters on a Restlet request?

开发者 https://www.devze.com 2022-12-23 02:41 出处:网络
What is the recommended way of setting GET query parameters on a Restlet Request object? I think I can see how to get them out of the request using getQueryAsForm(), but how do they get set in the fi

What is the recommended way of setting GET query parameters on a Restlet Request object?

I think I can see how to get them out of the request using getQueryAsForm(), but how do they get set in the first place?

At the moment, I am adding them manually to the URL using a StringBuilder and java.net.URLEncoder, but it seems like there should be a better way开发者_运维技巧.


Second attempt:

Reference reference = new Reference("http://127.0.0.1:8080/test"); 
reference.addQueryParameter("testParam", "testVal"); 
request.setResourceRef(reference);  
request.setMethod(Method.GET);

the addQueryParameter encodes the arguments automatically if needed.


request.getAttributes().get("key");

See also the tutorial (1.0, 1.1 or 2.0) on restlet.org

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号