【发布时间】:2013-08-12 11:47:27
【问题描述】:
我希望能够根据 GET 请求标头中的 Accept 类型调用某个方法。目前,我的资源类中有以下内容:
import org.restlet.resource.Get;
@Get("json")
public Representation getJson(Variant variant) throws Exception{
return new StringRepresentation("json");
}
@Get("xml")
public Representation getXml(Variant variant) throws Exception {
return new StringRepresentation("xml");
}
@Get("x-octet-stream")
public Representation getFile(Variant variant) throws Exception {
return new StringRepresentation("octet-stream");
}
我可以使用http GET成功调用方法getJson()和getXml(),并将Accept标头分别设置为application/json和application/xml。当我使用Accept 标头作为application/x-octet-stream 发出GET 时,将调用getJSon() 方法而不是使用x-octet-stream 注释的方法。你知道为什么吗?和/或如何调用getFile() 方法?
Rest 是否只允许您使用json 和xml 作为方法入口点?是否有公认类型的列表?我已经查看了该网站,但没有任何此类类型的列表。谢谢
【问题讨论】:
标签: java http rest get restlet