我正在使用 Apache-CXF 创建 REST 网络服务并尝试提交表单。
服务器:
这是我的方法,希望得到json数据。
@POST
@Path("/addCustomer/")
@Consumes(MediaType.APPLICATION_JSON)
//{"Customer":{"name":"Some Name","id":6}}
public Customer addCustomer(Customer customer){
logger.debug(customer);
return customer;
}
客户: 我正在使用 firefox REST 插件提交请求: 使用 REST 客户端,我发布了以下 json 作为请求正文:
{"Customer":{"name":"Arnav Awasthi","id":6}}
但我收到 “415:不支持的媒体类型”
。
最佳答案
使用 restclient,一个用于 fire fox 的插件,并将 http header 添加为 Accept:application/json,content-type: application/json。
关于java - 如何在 Apache CXF jax-rs (REST) 中提交 JSON 数据作为请求主体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5844394/