不支持的媒体类型(状态415)

时间:2017-12-27 10:18:16

标签: html spring-boot axios

我有一个应用程序问题/ x-www-form-urlencoded with my form。事实上,当我发送数据(以json格式)时,它们很好地通过执行它的方法恢复,除了我有这个错误浏览器中显示消息:

  

出现意外错误(type = Unsupported Media Type,   状态= 415)。内容类型   'application / x-www-form-urlencoded; charset = UTF-8'不支持

以下是我的不同代码:

从表单中检索数据并将其插入数据库的方法:

@RequestMapping(value = "/insert",method = RequestMethod.POST, consumes="application/json")
public @ResponseBody void createType(@RequestBody Type type) {
    typeService.createType(type);
}

HTML:

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Getting Started: Handling Form Submission</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
    <div id="app">
    <h1>TEST FORM</h1>
     <form action="" method="post">
        <p>Type description: <input type="text" v-model="type.description"/></p>
        <p><button v-on:click="addType()"> Send </button><input type="reset" value="Reset" /></p>
    </form>
    </div>


    <script src="http://cdn.jsdelivr.net/vue/1.0.10/vue.min.js"></script> 
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
      <script>
        Vue.prototype.$http = axios;
        new Vue({
            el:'#app',
            data:{
                type:{description:''}
            },
            methods:{
                addType(){
                    let newType = {description:this.type.description};
                    console.log(newType);
                    this.$http.post('/types/insert',newType).then(response => {
                        console.log(response);
                    });
                }
            }
        });
      </script>
</body>
</html>

我尝试了表单的不同enctype(text / plain,multipart / form-data和application / json; application / x-www-form-urlencoded是默认设置),但没有人允许我解决问题。

提前谢谢。

0 个答案:

没有答案
相关问题