【发布时间】:2016-06-06 10:44:05
【问题描述】:
我知道有一些线程有同样的问题,但是我没有让它正常运行。我对此还是很陌生。
我有一个 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/html Content-Type: text/htlm
谁有解决办法?
编辑:
在网上进行大量搜索后,我终于设法找出真正的问题是什么...... Glassfish 4.1.1 似乎有一个错误,是什么导致了在我的服务器上发帖时出现的问题...... .
【问题讨论】:
-
尝试设置
contentType: 'application/json', dataType: 'json' -
@gmaslowski 不适合我。仍然得到同样的错误
标签: java ajax post jax-rs oracle-jet