如何通过curl测试Jersey simple

如何通过curl测试Jersey simple,curl,jersey-2.0,Curl,Jersey 2.0,我在泽西岛上有一节简单的课。如何使简单的测试通过curl切换格式的返回类型?我不想写客户机 @Path("/hello") public class Hello { // This method is called if TEXT_PLAIN is request @GET @Produces(MediaType.TEXT_PLAIN) public String sayPlainTextHello() { return "Hello Jerse

我在泽西岛上有一节简单的课。如何使简单的测试通过curl切换格式的返回类型?我不想写客户机

@Path("/hello")
public class Hello {

    // This method is called if TEXT_PLAIN is request
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String sayPlainTextHello() {
        return "Hello Jersey";
    }

    // This method is called if XML is request
    @GET
    @Produces(MediaType.TEXT_XML)
    public String sayXMLHello() {
        return "<?xml version=\"1.0\"?>" + "<hello> Hello Jersey" + "</hello>";
    }

    // This method is called if HTML is request
    @GET
    @Produces(MediaType.TEXT_HTML)
    public String sayHtmlHello() {
        return "<html> " + "<title>" + "Hello Jersey" + "</title>" + "<body><h1>" + "Hello Jersey" + "</body></h1>"
                + "</html> ";
    }

}
@Path(“/hello”)
公共课你好{
//如果请求文本,则调用此方法
@得到
@生成(MediaType.TEXT\u PLAIN)
公共字符串sayplantextHello(){
返回“Hello Jersey”;
}
//如果请求XML,则调用此方法
@得到
@生成(MediaType.TEXT\u XML)
公共字符串sayXMLHello(){
返回“+”Hello Jersey“+”;
}
//如果请求HTML,则调用此方法
@得到
@生成(MediaType.TEXT\u HTML)
公共字符串sayHtmlHello(){
返回“+”+“Hello Jersey”+“+”+“Hello Jersey”+”
+ " ";
}
}
对于XML,请尝试以下方法:

curl -H "Accept: text/xml" -H "Content-Type: text/xml" -X GET "http://localhost:8080/yourapp/hello"

与text/html和text/plain类似,我建议使用Rest控制台浏览器插件而不是curl。