http接口使用ajax调用正常但restful工具调用406报错

使用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

clipboard.png

clipboard.png

多次检查后感觉应该没有问题,随后新建项目写测试代码,使用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调用的话该怎么配置?最好能提供截图谢谢

阅读 3.6k
1 个回答

jQuery.post默认的Content-Type是application/x-www-form-urlencoded,而你的是application/json

还是不行的话请查看 http://blog.csdn.net/hemingwa...

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题