ajax mediatype,JQuery/Ajax POST call, Unsupported Media Type

I get an

Unsupported Media Type - The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.

Strangely, if I look at the POST calls in firebug, they are indicated as not successfull, but if I do a "resend", they are sent and an answer is retrieved.

I already tried the accepted answer there: jquery ajax rest call - Unsupported Media Type - did not work for me.

-edit: If it helps, I use Moxy.

var sent = "This is a test request.";

var add = "testing..";

var request = { sentence: sent, addition: add };

$.ajax({

url: "http://localhost:8080/MyProject/Rest/Path/toPost",

type: "POST",

data: JSON.stringify(request),

contentType: "application/json; charset=utf-8",

dataType: "json",

success: function(resultData) {

//do stuff

},

});

This is my model:

@XmlRootElement(name = "request")

public class Request {

private String sentence;

private String addition;

public Request() {

this.sentence = "default";

this.addition = "default";

}

public Request(String sentence, String add) {

this.sentence = sentence;

this.addition = add;

}

public String getSentence() {

return sentence;

}

public String getAddition() {

return addition;

}

public void setSentence(String sentence) {

this.sentence = sentence;

}

public void setAddition(String addition) {

this.addition = addition;

}

}

@XmlRootElement(name = "answer")

public class Answer {

private ArrayList lsit;

private String info;

public Answer() {

this.list = new ArrayList();

this.info = "Good";

}

public Answer(ArrayList list, String info) {

this.list = list;

thisinfo = info;

}

public void setInfo(String info) {

this.info = info;

}

public String getInfo() {

return info;

}

public ArrayList getList() {

return list;

}

public void setList(ArrayList list) {

this.list = list;

}

}

And this is my Servlet:

@Path("/Path")

public class TestServlet {

@Path("/toPost")

@POST

@Consumes({MediaType.APPLICATION_JSON})

@Produces({MediaType.APPLICATION_JSON})

public Answer consume(Request request) {

ArrayList res = new ArrayList();

res.add(request.getSentence());

return new Answer(res, "Good");

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值