2013-02-26 99 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

相關問題