2013-02-26 101 views
0

我想使用泽西库建立一个RESTfull API,但它给了我一个例外。 这里是我的文档类不支持的媒体类型球衣RESTfull api

@XmlRootElement 
@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER) 
public class Docs { 

    @XmlElement(name = "field") 
    public String field; 

    @XmlValue 
    public String content; 

} 


@Path("/update") 
public class Update { 
    @POST 
    @Path("/xml") 
    @Consumes(MediaType.APPLICATION_XML) 
    @Produces(MediaType.APPLICATION_XML) 
    public String createIndexXML(Docs docs) 
      throws Exception { 
     System.out.println(docs.content); 
     return "It works"; 

    } 

} 

如果我尝试使用curl它抛出Error 415 Unsupported Media Type

curl -XPOST "http://localhost:8089/update/xml" -d '<docs> 
      <field>title</field> 
</docs>' 

回答

1

您需要的内容类型添加到您的请求头进行检查。添加-H "Content-Type: application/xml" to your卷曲调用。

我想你也将发现有与你的bean的注释问题 - 但这是另一个问题......

+0

我试过curl -H“Content-Type:text/xml”-X POST“http:// localhost:8089/update/xml”但我仍然遇到同样的问题 – Kathick 2013-02-27 05:47:38

相关问题