我知道有一些线程有同样的问题,但是我没有让它正常运行。我对此还是很陌生。
我有一个 JAX-RS 服务器正在运行:
该GET
方法有效。该POST
方法没有。
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response post(Movie movie){
System.out.println("In the POST method");
String result = movie.toString();
return Response.status(201).entity(result).build();
在我的 Oracle JET 客户端中,我想发表一篇文章:
addMovie = function(){
console.log("post sent");
$.ajax({
type: "POST",
url: "http://localhost:8080/MovieRestService/resources/movies",
headers: {
"Content-Type": "application/json"
},
data:
{
id: 2,
name: "test",
director: "test",
year: 234
},
success: "success",
dataType: 'application/json'
});
它一直给我一个415 Unsupported Media Type
错误。对我来说似乎有点奇怪的是,在响应标头中,内容类型是 text/htmlContent-Type: text/htlm
有人有解决方案吗?
编辑:
在网上进行大量搜索后,我终于设法找出真正的问题是什么...... Glassfish 4.1.1 似乎有一个错误,是在向我的服务器发帖时导致问题的原因......