在我开始使用Restlet之前,我已经写了一个Jersey客户端。这是非常直观的--看起来Restlet并非如此。没有太多的文档,我不能解决最简单的问题。
我所在的位置:
service = new ClientResource("http://localhost:8080/com-project-core/rest");
service.setChallengeResponse(ChallengeScheme.HTTP_BASIC, "admin", "geheima");
我从文档中得到了什么:
String myString = service.get(String.class);
或者打包一个资源:
ConnectedResourceIF connectedResource = service.wrap(ConnectedResourceIF.class);
这就是工作。但是如果这样呢:
A.当我想更改我的服务路径时?在新泽西,它就像是
service.path("foo").path("bar")
为
http://localhost:8080/com-project-core/rest/foo/bar
我想设置一个acceptHeader。在泽西岛就像是
service.accept(MediaType.TEXT_PLAIN)
C.我想设置查询参数。在泽西岛:
service.queryParam("1","foo").queryParam("2","bar")
对不起,希望有人能解决这个初学者的问题。我在restlet文档中找不到任何东西。
发布于 2012-07-09 15:03:21
对于A:
栏service.getChild(“/foo/
”,ConnectedResourceIF.class);
对于B(需要最新的2.1 RCx版本):
service.accept(MediaType.TEXT_PLAIN);
对于C语言(需要最新的2.1 RCx版本):
service.setQueryValue("1","foo");
service.setQueryValue("2","bar");
寻找这类东西的最好地方是Javadoc,因为这些API的更改是最近才发生的:http://www.restlet.org/documentation/snapshot/jee/api/org/restlet/resource/ClientResource.html
我们正在为下一个2.2版本编写一个新的深入教程。第一本完成"Restlet in Action“的书:)
https://stackoverflow.com/questions/11391680
复制相似问题