使用Spring MVC在Controller写了个post接口
@RequestMapping(value = "/ins", method = RequestMethod.POST)
public String ins(@RequestBody String requestBody) {
//过程略,结果会返回一个json字符串
}
假设访问路径为:http://localhost:8080/pass/A/ins
随后使用restful工具 Advanced rest client 进行调用,但是一直报错HTTP Status 406 – Not Acceptable
多次检查后感觉应该没有问题,随后新建项目写测试代码,使用ajax进行调用:
$.post({
url : "http://localhost:8080/pass/A/ins",
dataType : "json",
data : {
username : 'admin'
},
success : function(data) {
console.log(data);
}
});
测试可用,打印结果:{success: true, code: "000", msg: null, detail: null}
现在想问一下,如果想使用工具如Advanced rest client调用的话该怎么配置?最好能提供截图谢谢
jQuery.post默认的Content-Type是
application/x-www-form-urlencoded
,而你的是application/json
还是不行的话请查看 http://blog.csdn.net/hemingwa...