Unsupported Media Type (status 415)

為{幸葍}努か 提交于 2019-12-24 22:11:21

问题


I have an application problem / x-www-form-urlencoded with my form.In fact, when I send the data (in json format), they are well recovered by the method that does it except that I have this error message in the browser:

There was an unexpected error (type=Unsupported Media Type, status=415). Content type ‘application/x-www-form-urlencoded;charset=UTF-8’ not supported

Here are my different codes:

Method that retrieves the data from the form and inserts it into the database:

@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>

I tried the different enctype (text / plain, multipart / form-data and application / json; application / x-www-form-urlencoded being the default) of the form but none allowed me to solve the problem.

Thank you in advance.

来源:https://stackoverflow.com/questions/47990345/unsupported-media-type-status-415

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!